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

I have the following problem:

I have an embedded Java project in Eclipse with two main functions that I want to make runnable jars. These two jars have to share some code, so I cannot put them in separate projects. One jar is cms and one jar is the web server for android app to connect.

A Java project contains a folder with assets (images, videos ...) that are created when using the CMS. I would like them not to be included in the jar as they should be available as a folder in the same directory when you use the jar.

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

Now I export using Eclipse by right clicking my project> Export> check the box "Copy required libraries to subfolder next to generated JAR"> "Finish"

Thanks in advance for any help.

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

+3


source to share


2 answers


Ok, I solved both my problems:

problem 1: creating executable jar file without data folder in it

solution: copy assets folder to destination jar folder and temporarily delete jar folder from eclipse project. Now create an executable jar. After that, you can restore the folder in the project.



problem 2: creating 2 executable jar files that share the same dependencies with both of them, using the same folder for libs

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

0


source


Create a driver class with a main method like the one below:

public class Driver {
    public static void main (String[] args) {
        if (args[0].equalsIgnoreCase("optionForClass1")) {
            FirstClass.main(null);
        else {
            SecondClass.main(null);
        }
    }
}

      



to pass parameters to the corresponding core functions, you can use system properties, which are VM global. Access them with System.getProperty("String")

or what you have.

+1


source







All Articles