0

I am sure that this has been asked at some point and answered but all the questions I have reviewed either don't seem to apply to me or don't make sense.

I have not needed to utilize external jars and have always used just the JDK in the past but wanted to make sure I knew how to do this. I created an application to compute and validate a file checksum against another file and moved several functions to an external jar to reference in my code.

I am using IntelliJ as my IDE. I can compile and run the code just fine from IntelliJ but when I create the executable JAR file and run it, any function referenced in my JAR file is throwing a NoClassDefFoundError. I am not sure what I am doing wrong.

I have listed the Jar in the manifest Class-Path

Manifest-Version: 1.0
Class-Path: lib/Utilities.jar
Main-Class: net.rethfam.checksumChecker.Main

I have made sure the JAR file is listed in the Project Dependencies

And that it is to be exported in the JAR

I have even validated that the jar file is listed in the executable jar using jar tf

jar tf ChecksumChecker.jar
META-INF/MANIFEST.MF
lib/
lib/Utilities.jar
META-INF/
net/
net/rethfam/
net/rethfam/checksumChecker/
net/rethfam/checksumChecker/controllers/
net/rethfam/checksumChecker/controllers/MainScreenController$1.class
net/rethfam/checksumChecker/controllers/MainScreenController.class
net/rethfam/checksumChecker/images/
net/rethfam/checksumChecker/images/checkImage-128x128.png
net/rethfam/checksumChecker/images/checkImage-16x16.png
net/rethfam/checksumChecker/images/checkImage-256x256.png
net/rethfam/checksumChecker/images/checkImage-32x32.png
net/rethfam/checksumChecker/images/checkImage-512x512.png
net/rethfam/checksumChecker/images/checkImage-64x64.png
net/rethfam/checksumChecker/images/CheckSumIcon.ico
net/rethfam/checksumChecker/images/Origional/
net/rethfam/checksumChecker/images/Origional/checkImage-Orig.png
net/rethfam/checksumChecker/Main.class
net/rethfam/checksumChecker/views/
net/rethfam/checksumChecker/views/MainScreen.fxml
Utilities.jar

I am ultimately at a loss at this point and tired of hitting my head against this wall. I don't feel like it should be this difficult.

Caused by: java.lang.NoClassDefFoundError: rethfam/ultis/fileUtils
    at net.rethfam.checksumChecker.controllers.MainScreenController.handleFileChooser(MainScreenController.java:68)
    ... 58 more
Caused by: java.lang.ClassNotFoundException: rethfam.ultis.fileUtils
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 59 more
KReth
  • 11
  • 6
  • You need to check answers like this one https://stackoverflow.com/questions/219585/including-all-the-jars-in-a-directory-within-the-java-classpath – Alex Nikiforov Mar 30 '19 at 01:57
  • See https://stackoverflow.com/a/42200519/104891. – CrazyCoder Mar 30 '19 at 02:26
  • Thanks, @CrazyCoder I did not find this one in my searching but is the same answer I stumbled upon in my attempts to get it to work as I intended. – KReth Mar 30 '19 at 02:32

1 Answers1

0

I was able to finally figure it out after playing around with the artifacts settings in IntelliJ.

To keep from needing to have a separate folder or jar file alongside the executable JAR, instead of adding the JAR library to the output layout of the Artifact, adding it as an an extracted directory added the classes to the JAR and the application is able to successfully utilize the methods that were contained in the JAR library.

KReth
  • 11
  • 6