Search code examples
javaeclipsemavenjarrunnable

Create 2 runnable JARs who use the same libraries without having them twice


I have the following problem:

I have a back-end Java project in Eclipse with 2 main functions which I want to make runnable jars of. These two jars-to-be share some code so I can't put them in seperate projects. One jar is a cms and one jar is a webserver for an android app to connect to.

The Java project contains a folder with assets (pictures, videos, ...) which are created when using the CMS. I would like them not to be included in the jar as they need to be accessed as a folder in the same directory when using the jar.

The project uses quite some libraries, all different jars. I want the 2 jars I export to use the same folder with libraries. But when I export the 2 jars I need, they both have a folder with the same libraries in it and the folder has the name of the jar I exported with a _lib-suffix. Is it possible to have both of my jars use the same folder with libraries?

Now I export with Eclipse by right clicking my project > Export > check "Copy required libraries in a sub-folder next to the generated JAR" > Finish

Thanks in advance for any help.

EDIT: If I just temporarily delete the assets folder and copy paste it next to my jar, it doesn't get included in the jar and it still works. That just leaves the question how to make 2 jars use the same libraries?


Solution

  • Ok, I solved both my problems:

    problem 1: creating an executable jar file without assets folder in it

    solution: copy assets folder to jar destination folder and temporarily delete jar folder out of eclipse project. Now create executable jar. Afterwards you can restore folder in project.

    problem 2: creating 2 executable jar files who use the same dependencies with both of them using the same folder for libs

    solution: make the first jar file in eclipse by right clicking my project > Export > check "Copy required libraries in a sub-folder next to the generated JAR" > Finish. When choosing a name for the Jar, choose a name you want the libs folder to have. If I choose the name "project", the libs folder will be "project_libs". Export the jar and rename it however you like. Now create the second jar with the same name you created the first one with, "project" in this case. So if I choose "project" as name again, it will create the same folder "project_libs" and both of your jars will be able to use them. Just rename your second jar to whatever you like to name it.