How to make Eclipse package ONLY required libraries?

David Tabernero M. :

After developing a java app in Eclipse, I would like to deploy it by packaging it into a runnable .jar with only the minimum necessary by the main method and its dependencies.

I have several packages in my workspace I work with too, but do not need to be in the resulting .jar file.

Eclipse exportation snapshot

When I try to export, it clearly says that the required libs will be there, but also the other independent packages are inside too. (With the Export option happen exactly the same)

Package view snapshot

I choose to export only the Main class of the com.project... package, but also the test.project... has been packaged.

In the project I have both com... and test... packages obviously.

How could I force it to truly package only the required ones?

Thanks in advance.

TEMPORARY ANSWER (2019-07-03):

Seems that, for now, there is no way to achieve this automatically, thus the answer from @arnonuem seems a good workaround.

If better news, please feel free to improve this thread.

Thank you all.

arnonuem :

I would create an ANT file for this specific task. There you can freely customize which packages should be compiled into the jar and which not. Please inspire yourself reading this example.

For a general overview what i am talking about you could take a quick look into this. https://howtodoinjava.com/ant/ant-build-jar-file-example/

Please focus on

<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath"
        includes="src/path/to/TheClassToBeIncluded.java" />

For more detailed information on how to include or exclude files or packages you should refer to the documentation over here:

https://ant.apache.org/manual/Tasks/javac.html

At the bottom of this page there is a list with valid build parameters.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=142746&siteId=1