Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export of runnable Java Class to .jar file including only required dependencies [duplicate]

Possible Duplicate:
How to determine which classes are used by a Java program?

I have a Java project on Eclipse that contains a lot of Java classes. I want to export one of them to a .jar file but I ran into some problems.

I already read through some existing threads, but I didn't get the right answer for my requirement, because:

If I choose "Export to JAR file" I get the right class exported, but the .jar file does not contain the required dependencies to run the jar file.

If I choose "Export to runnable JAR file" the resulting jar file contains all dependencies but also puts in all the other classes from the whole project (also those that I don't need).

How can I export the single Java class to a .jar file that includes also required libraries for running the jar file? The resulting jar file has to be as small as possible.

Thanks a lot.

like image 245
fachexot Avatar asked Jun 18 '12 16:06

fachexot


1 Answers

You could create a new project with only the class that you need in it and export that project as a runnable jar.

like image 64
Poindexter Avatar answered Sep 30 '22 16:09

Poindexter