Search code examples
javaeclipsemavenmaven-2m2eclipse

Maven: How to package local jar into final jar?


I have an eclipse-maven project.
I need my local ojdbc7.jar to be packaged into my final jar.
I am able to pack the downloadable dependencies into the final jar, but unable to pack the local jar in the final jar because <scope>system</scope> is added in its <dependency>.
Here is the POM.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.comcast.mongo</groupId>
  <artifactId>MongoRead</artifactId>
  <version>0.1</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>2.2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
             <groupId>org.apache.spark</groupId>
             <artifactId>spark-sql_2.11</artifactId>
             <version>2.2.0</version>
         </dependency>

        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.8</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.mongodb.spark</groupId>
            <artifactId>mongo-spark-connector_2.11</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>bson</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc</artifactId>
            <version>7</version>
            <scope>system</scope>
            <systemPath>${basedir}/ojdbc-7.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>org.clojure</groupId>
            <artifactId>java.jdbc</artifactId>
            <version>0.7.0</version>
        </dependency>

    </dependencies>


    <build>
    <plugins>
      <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2.1</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> 
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>

</project>

I have provided <scope>provided</scope> for those dependencies which I do not need to be packaged inside my final jar. But because <scope>system</scope> needs to be set for <systemPath>, I am unable to package this local jar inside final jar.
Please suggest how do I do that ?


Solution

  • You could install your ojdbc library into your maven repository, it would then work the same as your other libs.

    Assuming you launch this command in the same location of your jar :

    mvn install:install-file -Dfile=ojdbc-7.jar -Dpackaging=jar -DgroupId=com.oracle -DartifactId=ojdbc -Dversion=7
    

    And in your POM, update to :

    <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc</artifactId>
            <version>7</version>
        </dependency>