简体   繁体   中英

Runnable jar not finding libraries

I have a project which has some dependent jars. I've added the dependent jars to project and then added them to build path. When I run it from eclipse, it runs fine.

Now I want to make this into a runnable jar. Once I export it as Runnable jar along with option "Package required libraries into generated Jar".

When I run the jar, It throws me Cannot find symbols error. These symbols are there in the dependent jars and I don't know why it's happening.

Can anyone help me out ?

You should use the option Extract required libraries into generated JAR rather than Package required libraries into generated Jar when you are exporting the project to a Runnable JAR file .

The difference is that for packaging the required libraries it will take the JAR files and put them inside your JAR file. So the JAR file have other JAR files in it. For this to work your main program has to have intimate knowledge on how to read those JAR files in the main JAR file.

To clarify, the result file will look like this:

project.jar/
   com/yourproject/Main.class
   dependencyA.jar
   dependencyB.jar

For the other option, the Extract required libraries into generated JAR , what will happen is that those dependencies will be unpacked and then packed into the JAR files. This time not as JAR files but as the class and resources files. This method will allow Java to find dependent class files from your main JAR file.

The result now will look like this

project.jar/
   com/yourproject/Main.class
   com/dependencyA/SomeClass.class
   com/dependencyA/SomeOtherClass.class
   ...

This format will be readable to the Java process that will look for class and resource files in a JAR not the nested JAR files.

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