0

So I have a small maven project in eclipse, if I export a runable JAR and select:

  • Package required libaries into generated JAR

it works fine.

I should note that one of my JAR's is maven controlled (Univocity) the other is a local Oracle JDBC JAR. I want to include both of these in my runable JAR package so I can deploy a single JAR to production and execute it with a single command.

In my POM I added maven-assembly-plugin and when I use mvn package, I get a JAR with the Univocity library, but it skips the Oracle JAR.

How can I get it to bundle the Oracle JAR into the final output ?

Here is the POM:

<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>au.com.myco</groupId>
  <artifactId>MyCoOracleExtractor</artifactId>
  <version>0.0.4</version>
  <packaging>jar</packaging>

  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <univocity.version>2.0.0</univocity.version>
  </properties>  

  <dependencies>
    <dependency>
      <groupId>oracle.jdbc</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0.4</version>
      <type>jar</type>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/ojdbc6-11.2.0.4.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>com.univocity</groupId>
      <artifactId>univocity-parsers</artifactId>
      <version>${univocity.version}</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
        </configuration>
      </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
        <executions>
                <execution>
                  <id>assembly:package</id>
                  <phase>package</phase>
                  <goals>
                <goal>single</goal>
            </goals>
                  <configuration>
                    <archive>
                      <manifest>
                        <mainClass>au.com.myco.MyCoOracleExtractor</mainClass>
                      </manifest>
                    </archive>
                    <descriptorRefs>
                      <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                  </configuration>
          </execution>
        </executions>
        </plugin>
    </plugins>
  </build>
</project>

I did try using maven-dependency-plugin, but it didnt solve the problem bundling them into the single JAR.

Exie
  • 466
  • 5
  • 16
  • Just a note - When I export the runable JAR in eclipse, it includes a: **org.eclipse.jdt.internal.jarinjarloader.** I presume this library handles unpacking the bundled JAR's. – Exie Mar 23 '16 at 01:23
  • Possible duplicate of [Maven assembly plugin and adding system dependencies to the classpath](http://stackoverflow.com/questions/2531354/maven-assembly-plugin-and-adding-system-dependencies-to-the-classpath) – A_Di-Matteo Mar 23 '16 at 10:32

1 Answers1

0

You have to install it manually because Oracle didn't let maven got any of their jars : so you got to install it manually with the command mvn install:install -Dfile=<path to file> ... and put it in your pom.xml like any other dependency without the <SystemPath> like this :

<dependencies>
    <dependency>
      <groupId>oracle.jdbc</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0.4</version>
    </dependency>
</dependecies>

In my case : when i want to deploy my application in tomcat : i got to put the jar ojdbc6 directly in the folder lib of tomcat.

Hohenheim
  • 1,545
  • 1
  • 12
  • 28