Eclipse: package of several projects in one JAR

I have several projects, but only one with the Main class. One that has a main class depends on other projects. These projects are mentioned in Eclipse, but when I export the JAR, other projects are not exported with this JAR.

How can I export my main project and "include" other projects in the same JAR? I would prefer not to have multiple JARs and should define them in my classpath on the command line.

+4
source share
3 answers

Do not do it with difficulty. Use Eclipse's own exporter. First, make sure that you have other projects referenced by the projects in the main project, "Build Path." Having done this, just right-click the main project, select Export, and then Java> Runnable JAR file. Select the launch configuration (which you used to test the main() class locally), and then you have 3 options for processing the library to package the JAR:

enter image description here

The first option simply repackages the classes of other projects inside the JAR. Everything is just thrown together.

The second option will copy other projects as a JAR inside the JAR. This usually does not work, but Eclipse also adds a special launcher that basically copies the embedded JAR files to memory, extracts them, adds the files to the class loader, and then calls main() with this class loader.

The third option is what you do not want for this particular case.

+8
source

I think that Eclipse uses ant and build.xml scripts for Java projects initially, Maven can be used, and in both cases there are ways to combine them into one jar, this thread answers the same question, I think:

A clean way to combine multiple cans? Ant preferred

+1
source

If I did, I would mine the projects using the maven dependency for each project dependency, and then use

 mvn assembly:assembly 

see http://maven.apache.org/plugins/maven-assembly-plugin/ for more information about this plugin

+1
source

Source: https://habr.com/ru/post/1369342/


All Articles