0

I have a java/maven project that runs some database stuff perfectly (classpath is working great). I use a proprietary database jar in order to connect to the database. When I go to package up my software into a shaded jar the proprietary jar isn't referenced. When I check the log files I see this error:

Exception: java.lang.ClassNotFoundException: com.sybase.jdbc4.jdbc.SybDriver

I'm trying to put everything into a shaded jar using Maven. Is there something that I'm not doing? Why is the database jar not working in my new shaded jar?

Adding the shade plugin configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.3</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <transformers>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>package.class</mainClass>
                    </transformer>
                </transformers>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>launcher</shadedClassifierName>
            </configuration>
        </execution>
    </executions>
</plugin>

I have followed the instructions about setting up a file repository since we don't have a corporate repository.

I created a folder at c:\my-repo and put the lone jconn4.jar file inside. I then added this to my pom.xml:

<repositories>
    <repository>
        <id>my-local-repo</id>
        <url>file://${basedir}/my-repo</url>
    </repository>
</repositories>

and

<dependency>
    <groupId>company</groupId>
    <artifactId>jconn4.jar</artifactId>
    <version>16.0</version>
</dependency>

Finally, at a command prompt I ran the command:

$ mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file -Dfile=C:\my-repo\jconn4.jar -DgroupId=company -DartifactId=jconn4.jar -Dversion=16.0 -Dpackaging=jar -DlocalRepositoryPath=C:\my-repo
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building My_Project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ My_Project ---
[INFO] Installing C:\my-repo\jconn4.jar to C:\my-repo\company\jconn4.jar\16.0\jconn4.jar-16.0.jar
[INFO] Installing C:\Users\jsmith\AppData\Local\Temp\mvninstall7806841451724024532.pom to C:\my-repo\company\jconn4.jar\16.0\jconn4.jar-16.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.613 s
[INFO] Finished at: 2016-12-08T10:26:08-05:00
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------

That's all well and good but I keep getting this error in my pom.xml now "Missing artifact company:jconn4.jar:jar:16.0"

enter image description here

Have I implemented something incorrectly?

Anton
  • 761
  • 17
  • 40
  • 1
    Post your `maven-shade-plugin` configuration. – Tunaki Dec 07 '16 at 21:41
  • @Tunaki, okay, added my configuration. I thought I had it correct, but perhaps not. – Anton Dec 08 '16 at 14:09
  • It looks like a missing dependency. – Mickael Dec 08 '16 at 14:16
  • @MickaëlB - a missing dependency with the shade plugin? Or are you saying it's a missing dependency declaration? – Anton Dec 08 '16 at 14:35
  • 1
    Which JAR are you launching? You should start the `*-launcher.jar`. Or the `SybDriver` class is simply not on your classpath. – Tunaki Dec 08 '16 at 14:36
  • @Tunaki, yep. I'm launching the *-launcher.jar. – Anton Dec 08 '16 at 14:37
  • 1
    Then most likely the `com.sybase.jdbc4.jdbc.SybDriver` just isn't there. Make sure you have a dependency on this JDBC driver. Also, you can unpack the JAR and check its content to see if the class is there. – Tunaki Dec 08 '16 at 14:37
  • @Tunaki, I have tried 1) adding the dependency in the pom.xml for a file on the system "\\server\folder\jconn4.jar" but the jar wasn't picked up. So I then tried 2) adding the jar file to the classpath and specifying a location on my local driver. That didn't work either. The funny thing is that the program runs perfectly from the IDE. It just won't hit the db when I run it from the jar. – Anton Dec 08 '16 at 14:40
  • @Tunaki, I unpacked the jar and the jconn4.jar file isn't there. I'm not sure what else to try to get the jar attached. Any suggestions? – Anton Dec 08 '16 at 14:46
  • 1
    `systemPath`? Noooooo [don't do that.](http://stackoverflow.com/questions/3642023/having-a-3rd-party-jar-included-in-maven-shaded-jar-without-adding-it-to-local-r) This is your issue. Wherever you read you should use `system`, disregard that source right now. – Tunaki Dec 08 '16 at 14:51
  • @Tunaki, you are a master at finding some of these posts on stack! I'll let you know how it goes! – Anton Dec 08 '16 at 15:00
  • Post `mvn dependency:tree` output. – lexicore Dec 08 '16 at 15:32
  • @Tunaki, I added some more information on my post. What am I doing wrong? – Anton Dec 08 '16 at 15:46
  • 1
    You installed to `C:\my-repo`, is that the repo you're using in your POM? – Tunaki Dec 08 '16 at 15:51
  • @Tunaki I thought that ${basedir} meant "C:\" but now I realize that it means the base path of the project. I have created the my-repo folder in the project path but still getting the same issue. – Anton Dec 08 '16 at 17:08
  • @Tunaki, okay I figured it out. I didn't have the jar file in the right location. – Anton Dec 08 '16 at 18:33

0 Answers0