Why does Eclipse export my entire project as runnable JAR file?

eclipse, jar, java

Solution

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.

Problem

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.

Original source