Reputation: 1376
Below is my Jar structure. This is standalone jar.
MyApp.jar
--> .settings
--> com
--> lib
--> META-INF
--> resources
--> .classpath
--> .project
I am attempting to execute this jar file from bat file.
I have mentioned classpath and main class in MANIFEST.MF file under META-INF folder from MyApp.jar
Manifest-Version: 1.0
Class-Path: ./lib/jar1.jar ./lib/jar2.jar ./lib/jar3.jar
Main-Class: com.bank.Main
Inside my bat file: java -jar D:\app\MyApp.jar
Is it correct way to lib folder inside jar?
But still i am facing ClassNotFoundException.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/JMSException
Anything i missed out Please advise me.
Upvotes: 1
Views: 373
Reputation: 502
Fat jar is not supported in Java by default. There are two options.
You can define a custom class loader which has to load jars inside lib directory programmatically.
You can manually merge all packages of jars inside lib directory to make a one jar and run it. Refer [https://dzone.com/articles/java-8-how-to-create-executable-fatjar-without-ide ]
Upvotes: 1
Reputation:
Put the lib folder outside of your current main jar [MyApp.jar] directory and execute it.
You have packaged the jar dependency inside your main jar. The intention of Class-Path is to add an external jar to the classpath, with the path relative to the location of the main jar.
Packaging a jar within a jar is not supported by standard Java classloaders. If you want, you can explode the inner jar into the main jar, though. Maven can do this for you.
Upvotes: 2