Jordi
Jordi

Reputation: 23187

Maven: Local dependecy file not found into war/WEB-INF/lib

I've added my local dependency library (jar file):

<dependency>
    <groupId>com.oracle.jdbc</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>12.1.0.2</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/ojdbc7-12.1.0.2.jar</systemPath>
</dependency>

Everything works fine, up to when maven generates war artifact.

I've look up inside generated war file, but, jar dependency is not there inside.

Any ideas?

I know I'm able to use maven installfile. I need to focus the problem using this kind of dependency declaration.

Upvotes: 0

Views: 434

Answers (3)

Rajendra Gupta
Rajendra Gupta

Reputation: 379

Dependencies in compile scope are automatically added to the target's WEB-INF/lib as part of the Maven build. Dependencies in system scope are not, dependencies with a system scope must be explicitly provided by definition. More information on below URL

Maven 2 assembly with dependencies: jar under scope "system" not included

Upvotes: 0

Grim
Grim

Reputation: 1974

A WAR is an web archive for Servlet Containers like Tomcat, Glassfish, JBoss (...). They are specified by the Servlet Specifications. The specs point out that the Datasources (Database) is in the Field of the Servlet-Containers.

(...) type javax.sql.DataSource for which the reference to the data source is injected by the container prior to the component being made available to the application.

You should place the database-driver to the servlet-container, not the web-application.

Upvotes: 0

JMSilla
JMSilla

Reputation: 1449

From Maven documentation :

system: This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

provided: This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

It seems that system scope needs the container or JDK to provide the dependency as the provided scope. Because of that, the dependency is not packed into the WAR file.

You can pack the dependencies into the lib folder using maven-war-plugin like this:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        ...
        <webResources>
            <resource>
                <directory>libs</directory>
                <targetPath>WEB-INF/lib</targetPath>
                <includes>
                    <include>ojdbc7-12.1.0.2.jar</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>

Upvotes: 0

Related Questions