简体   繁体   中英

Jar file referencing Maven jar file doesn't work consistently

I have a Swing application that uses classes from Maven artifact math.geom2d:javaGeom:0.11.1 . To create a jar file in A GitHub Release I use a modified "fatJar" build.gradle task, so the geom2d classes are included in the jar file. For the jar file for my application on Maven, I don't include the geom2d classes, so these classes don't show up in that jar file, but they are referenced as dependencies.

What is odd is that on my machine this (smaller) jar file works fine consistently, so I thought everything was OK, even if strange. I decided to try it on my wife's machine and it crashes with a NoClassDefFoundError. I thought maybe it was because she didn't have Maven installed.., tried installing it, but no difference! Help would be appreciated!

Here is the pom.xml on Maven for my app:

<project 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.jpaulmorrison</groupId>
<artifactId>drawfbp</artifactId>
<version>2.18.4</version>
<name>DrawFBP</name>
<description>Diagramming Tool for Flow-Based Programming</description>
<url>https://github.com/jpaulm/drawfbp</url>
<licenses>
<license>
<name>GNU Lesser General Public License, Version 3.0</name>
<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<id>jpaulmorr</id>
<name>
John Paul Rodker Morrison (Software architect/developer)
</name>
<email>jpaulmorr@gmail.com</email>
</developer>
<developer>
<id>bobcorrick</id>
<name>Bob Corrick (Software architect/developer)</name>
<email>bobcorrick@outlook.com</email>
</developer>
</developers>
<scm>
<connection>scm:git:https://github.com/jpaulm.git</connection>
<developerConnection>scm:git:https://github.com/jpaulm.git</developerConnection>
<url>https://github.com/jpaulm.git</url>
</scm>
<dependencies>
<dependency>
<groupId>math.geom2d</groupId>
<artifactId>javaGeom</artifactId>
<version>0.11.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

Thanks @samvel1024: I now have a better handle on what is going on:

  • the jar file without the geom2d classes could run because I had geom2d in my classpath - it doesn't any more!

  • I create a fatJar using a task in build.gradle, but uploadArchives creates a new jar file, which isn't "fat"!

  • so, I would either like to add the fatJar task to my uploadArchives function,

OR

  • suppress the 'jar' task in uploadArchives, so it doesn't mess up the "fat" jar that I already have. I have tried "jar,enabled = boolean variable". but I can't set it to "false"...

Either of these two options should be easy in a sensible language, but I can't get either to work! Help would be appreciated!

If you are going to use maven for building the jar, then you need to include all the dependencies as you have in your gradle build def.

If you want the jar to be runnable with java -jar my.jar then, additionally you need to use some build plugin to do that for you.

You can find more details here

Turned out to be so simple: Turned out to be the second option above:

"... suppress the 'jar' task in uploadArchives, so it doesn't mess up the "fat" jar that I already have. ..."

Add -x jar to the command line for uploadArchives!

Thanks anyway, @samvel1024 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM