0

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!

Paul Morrison
  • 1,694
  • 3
  • 20
  • 35
  • I think there's no way to infer exactly how the jar file is generated. Can you please add that part of the pom.xml as well ? It should be a build plugin I suppose. – samvel1024 Nov 04 '19 at 19:30
  • It might also help to list the content of the jar and post the relevant pieces. You can use `tar -tf my-example.jar` for that. Look for the class that was causing `NoClassDefFoundError` – samvel1024 Nov 04 '19 at 19:32
  • @samvel1024 That's the whole pom.xml - it's generated by build.gradle - that's at https://github.com/jpaulm/drawfbp/blob/master/build.gradle - maybe it's missing something important...? – Paul Morrison Nov 04 '19 at 22:14
  • When the math package is in the app jar file, it works fine! I guess what I don't understand is how the app locates the relevant classes when the math package is missing from the jar file - somehow it manages to do that on my machine, but not on my wife's! TIA – Paul Morrison Nov 04 '19 at 22:17

2 Answers2

0

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

samvel1024
  • 1,123
  • 4
  • 15
  • 39
0

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 !

Paul Morrison
  • 1,694
  • 3
  • 20
  • 35