Reputation: 1155
I have a Java project called Project1, containing some ten packages. In package3, I have a class called MyPrgm
which I want to export as a runnable jar. This is fine and I can execute it in the command prompt / using a batch file.
However, when I open MyPrgrm.jar
archive using WinRAR I realize that every single class in Project1 is in the archive; is there a way to export only the classes that are required for the program to run? I am using Eclipse IDE.
Upvotes: 11
Views: 5925
Reputation: 10900
If you don't want all the classes in the JAR, then choose export only for that particular package, not for the entire project.
Even if the above doesn't work (no reason why it shouldn't), you can still remove the additional classes from the executable. JAR is basically a ZIP archive, you can open it with any archive manager and add/remove files as you wish.
Upvotes: 1
Reputation: 285405
It does this because you told it to. If you only want to export one package, then only export one package. For instance, if you right click on the project and press Export, Eclipse will try to export everything in the project, but you can fine tune this easily via the export wizard. If you right click on a package and click Export, then Eclipse will try to export only that package.
In particular look at the "Jar File Specification" portion of the Export wizard where you can pick and choose what to export.
Upvotes: 5