Download creating a jar file from your java application

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CREATING A JAR FILE FROM YOUR JAVA APPLICATION
What is a jar file?
In Java terminology, jar stands for Java Archive. A jar file is essentially a zip file that
can be opened with a zip utility such as WinZip or WinRAR. It contains all the compiled
code (.class files) and any other resources (such as .GIF images) that are needed to run
the application. It can also contain java source code if you want it available to the user.
Naming a jar file:
A jar file is typically named as the application with a .jar extension. For example, if you
are creating a minesweeper game, you may want to name it MineWorld.jar.
Creating a jar file:
Here are the instructions for creating a jar file:
1. Develop your application in eclipse as you normally do. As normal, create a separate
package for your new application in this project.
2. If you normally use a jar file in your application, such a gridworld.jar, you will need
to extract the source code from the jar and save that in the proper folders in your
project. For example, if you are creating a GridWorld application, you should create
the following packages in your project (note: you can drag the info folder from the S:
drive to your project in eclipse and it will create these packages for you):
3. When you are satisfied that it is working correctly, you can then create the jar file.
Highlight all the folders in your project, then right click and select Export…
Note: You do not have to highlight any text files that reside in the project directory,
since these will need to be separate from the jar file.
4. Since you are exporting to a jar file, select JAR file and press the Next> button:
5. The JAR File Specification window will appear. Make sure that all your packages
are clicked. Also, make sure that “Export generated class files and resources” is
clicked. The Export destination is the name and location for the generated jar file.
Optionally, you may also want to click “Export Java source files and resources” if
you want the jar file to include the source code (.java files). Press the Next > button.
6. The JAR Packaging Options window will appear. I normally click on both of the
“Export class file” options. Press the Next > button:
7. The JAR Manifest File window will appear. The manifest file is used to identify the
client class to startup your Java application. At the Main class prompt, you should
select this client class (it will list all the classes that contain main() methods. Press
Finish to create the jar file:
Opening a jar file:
As mentioned above, a jar file is essentially a zip file. You can open the jar file to see the
files that it contains.
1. To do this, right click on the jar file and select Open With… Then select an unzip
program such as WinZip or WinRAR.
2. The list of folders/files contained in the jar file will then be displayed:
3. Double click on a folder to see the classes and other resources contained in the folder:
CREATING AN EXECUTABLE (.EXE) FILE FOR YOUR JAVA APPLICATION
What is an Executable file?
An Executable file is a single file that contains all of the Java code and can be run by
simply double clicking on the file. This makes it an easy process for delivering and
running your Java application. An executable file must have the extension .exe .
Prerequisite:
A prerequisite is that the computer you are trying to run the Java application on must
have Java Runtime Environment (JRE) software installed on it. This is normally the case
on most computers since java code is used for many common applications.
JSmooth software:
JSmooth is free software that can be downloaded from the internet. This software allows
you to convert your Java application to an executable file. The download is standard and
you should be able to follow the instructions. Here is the link:
http://jsmooth.sourceforge.net/download.php . Click the “visit download page” link.
Note: Instead of downloading, you can copy the JSmooth folder from
S:\StudentShare\AP Computer Science. Here is what the download page looks like:
How do you convert a Java Application to an executable file?
The following instructions show you how to use the JSmooth software to convert your
Java application to an executable file. Before doing this you should have already creating
a jar file of your Java application. See the previous pages in this document for those
instructions.
1. Launch the JSmooth software which you should have already loaded on your PC.
2. Select Skeleton to determine the type of executable wrapper to use. There are 5
different options to choose from. To determine which one is appropriate for your
application, click on the question mark bubble. If the application is not printing
anything to the console, you could use the Autodownload Wrapper. You would not
normally need any Skeleton properties.
3. Select the Executable screen to specify the name/location of the executable file that
you are generating. In the Executable Binary field, select the folder and type in the
name of the executable file. Good practice is to name it the same as your project
name. Note that it should have an .exe extension. Also, you should click the
checkbox to set the executable folder as current directory of the application.
4. Select the Application screen and complete the information to tell JSmooth which
Java application files to use.
a. In the Classpath section, click on
your application.
and select the jar file generated for
b. In the Application Settings section, in the Main class box click on the client
class that you want to launch in order to run the application.
c. Click on the Embedded jar option and specify the jar file that you want to embed
into the executable file. This is normally the same jar file that you entered in the
Classpath section. Embedding the jar file will save all your compiled code to this
one executable file.
5. You will want to save this JSmooth information to a JSmooth project (so that you
don’t have to type it again if you want to regenerate the exe file). Press the
icon
and then identify where you want to save this information. It is recommended that
you name it the same as your executable file without the .exe extension. JSmooth
will save it with the .jsmooth extension.
6. You are now ready to generate the exe file. Press the
icon to create the file.
7. If this is successful, you have generated an executable file which you can simply
double click on to run the Java application.
8. Create a subfolder in S:\StudentShare\AP Computer Science\Year-End Project
Applications to store your application. Copy the executable file and any text file(s) in
your project that your application is using, to this folder. Now this application can be
enjoyed by others if they download the contents of this folder.