Tutorial - Eclipse: Exporting to Jar
Exporting to JAR files under Eclipse
This is a brief tutorial on how to export your eclipse project to a JAR file. Essentially, a JAR file is a single file which packages up all of your project files into one. You can also run your application directly from the JAR file.
To begin the process, select "File > Export" from the eclipse menu. This will bring up the following screen:
Select JAR from the list and click "Next":
The window is asking you what to include in the JAR file. In this case, we have two projects to choose
from (lab1 and Test). Select the project you want to include by clicking on the check box to its left. At
this point, you need to choose whether or not to include souce code in the JAR file.
For lab submission, you must include the source code --- so, check the "export Java source files and resources" box. This allows us to see your source code and check that it compiles (which is important). The "export generated classfiles and resources" should be checked by default. If not, then you should check this as well. You also need to provide a name for the JAR file, although the default value should be OK in most cases. Don't
press "Finished" yet! There is one more thing to do, so click on "Next":
You shouldn't have to do anything in this window, so click "Next" again:
At this point, you need to specify which class should be used as the application entry point. This is the class which contains the "static public main()" method. In the above, "GreatestCommonDivisor" has been
entered, which correct for the first lab.
Finally, you should test that your JAR file has been built correctly. Do to this, run it from the command-line like so:
You'll need to replace "lab1.jar" with whatever you've named your JAR file. Finally, check that your JAR file contains the source files:
Here, "-tvf" tells the command-line tool "jar" to print the contents of the archive. We can see that "GreatestCommonDivisor.java" is there, so everything looks good. To find more information on the "jar" tool,
run "jar --help".
Starting up | Hello World | Running Programs | Debugging | Advanced Debugging