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.
FYI: In simple terms, the difference between a JAR file and a Runnable JAR is that while a JAR file is a Java application which requires a command line to run, a runnable JAR file can be directly executed by double clicking it.
A runnable jar file allows a use to run Java classes without having to know class names and type them in a command prompt, rather the user can just double click on the jar file and the program will fire up. A runnable jar allows Java classes to be loaded just like when a user clicks an exe file.
Launch configurations are presumably used because they describe the main class you want to run, and the libraries the main class needs. They are created automatically when you run your main class inside Eclipse.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With