0

This is my java project structure

lib/*.jar
manifest.txt
Mytest.java

I follow theses steps to create a jar

1. javac -cp .:lib/* Mytest.java
2. jar -cvfm mytest.jar manifest.txt Mytest.class lib

Now run the jar file

java -jar mytest.jar

It works fine.

However, if I delete the lib folder, then run the jar file, it won't work

rm -rf lib
java -jar mytest.jar
Error: Unable to initialize main class Mytest
Caused by: java.lang.NoClassDefFoundError: org/orekit/frames/Frame

It appears java still tries to find the dependencies in the local path instead of the archived jar file.

Gary Allen
  • 385
  • 1
  • 3
  • 11
  • *jar -cvfm mytest.jar manifest.txt Mytest.class lib* That won't cut it. You can't jar jars into jars [sorry I couldn't resist that sentence ;) ] as the classloader won't find the dependencies. There are special tools for that to create so-called 'fat jars' such as Maven 'Shade' – g00se Aug 12 '23 at 12:44

0 Answers0