SlideShare a Scribd company logo
2
Most read
Creating an Executable jar File
In Java, it is common to combine several classes in one .jar ("java archive") file.
Library classes are stored that way. Larger projects (such as the Case Study in
the AP program) use jar files. You can create your own jar file combining several
classes, too.

jar files are created using the jar.exe utility program from JDK. You can make your
jar file runnable by telling jar.exe which class has main. To do that, you first need to
create a manifest file. A manifest is a one-line text file with a "Main-Class"
directive. For example:
Main-Class: DanceStudio

This line must end with a newline.

A jar file created with a main class manifest can be used both as a library and a
runnable jar. If you use it as a library, you can edit and compile any of the classes
included in the jar, and add it to your project. Then it will override the one in the
jar file.

You can create a manifest file in any text editor, or even by using the MS-
DOS echo command. You can give your manifest file any name, but it’s better to
use something standard, such as manifest.txt.

Once you have a manifest and all your classes have been compiled, you need to
run JDK’s jar.exeutility. It is located in the JDK’s bin folder, the same place
where javac.exe and java.exe. are. jar.exe takes command-line arguments; if you run it
without any arguments, it will display the usage information and examples. You
need
Cmywork> jar cvfm MyJarName.jar manifest.txt *.class

cvfmmeans "create a jar; show verbose output; specify the output jar file name;
specify the manifest file name." This is followed by the name you wish to give to
your jar file, the name of your manifest file, and the list of .class files that you want
included in the jar. *.class means all class files in the current directory.

Below are the detailed steps for doing this in Command Prompt and in JCreator.

Creating a jar File in JCreator
You can configure a "tool" that will automate the jar creation process. You only
need to do it once.

   1.   Click on Configure/Options.
   2.   Click on Tools in the left column.
   3.   Click New, and choose Create Jar file.
   4.   Click on the newly created entry Create Jar File in the left column under Tools.
   5.   Edit the middle line labeled Arguments: it should have
        cvfm $[PrjName].jar manifest.txt *.class

   6. Click OK.

Now set up a project for your program, create a manifest file manifest.txt or copy
and edit an existing one. Place manifest.txt in the same folder where the .class files
go. UnderView/Toolbars check the Tools toolbar. Click on the corresponding tool
button or press Ctrl-1 (orCtrl-n if this is the n-th tool) to run the Create Jar File tool.

With Windows Explorer, go to the jar file that you just created and double click on
it to run.

Creating a jar File in Command Prompt

   1. Start Command Prompt.
   2. Navigate to the folder that holds your class files:
        C:>cd mywork

   3. Set path to include JDK’s bin. For example:
        C:mywork> path c:Program FilesJavajdk1.5.0_09bin;%path%

   4. Compile your class(es):
        C:mywork> javac *.java

   5. Create a manifest file:
        C:mywork> echo Main-Class: DanceStudio >manifest.txt

   6. Create a jar file:
        C:mywork> jar cvfm DanceStudio.jar manifest.txt *.class
7. Test your jar:
   C:mywork> DanceStudio.jar

More Related Content

PPTX
Java swing
PPTX
Simple object access protocol(soap )
PPTX
Event Handling in java
PPT
Java Streams
PDF
PPTX
Android Layout.pptx
PPTX
Event handling
Java swing
Simple object access protocol(soap )
Event Handling in java
Java Streams
Android Layout.pptx
Event handling

What's hot (20)

PPT
Java API: java.net.InetAddress
PPS
Java rmi
PPTX
Abstract Class & Abstract Method in Core Java
PPT
Java EE Introduction
PPTX
Type casting in java
PPT
Textbox n label
PPTX
Rmi presentation
PPT
3. distributed file system requirements
PDF
Android intents
PPTX
Access specifiers(modifiers) in java
PPTX
Basics of Object Oriented Programming in Python
PDF
Remote Method Invocation (RMI)
PPTX
A PRESENTATION ON STRUTS & HIBERNATE
PPTX
Http Server Programming in JAVA - Handling http requests and responses
PPTX
servlet in java
PPTX
Java beans
PPTX
Database connectivity in python
PPSX
JDBC: java DataBase connectivity
PPTX
IPV6 ADDRESS
Java API: java.net.InetAddress
Java rmi
Abstract Class & Abstract Method in Core Java
Java EE Introduction
Type casting in java
Textbox n label
Rmi presentation
3. distributed file system requirements
Android intents
Access specifiers(modifiers) in java
Basics of Object Oriented Programming in Python
Remote Method Invocation (RMI)
A PRESENTATION ON STRUTS & HIBERNATE
Http Server Programming in JAVA - Handling http requests and responses
servlet in java
Java beans
Database connectivity in python
JDBC: java DataBase connectivity
IPV6 ADDRESS
Ad

Viewers also liked (13)

PDF
Modernization in Eclipse
PPTX
Japp klingemann reaction
PPTX
Jar signing
PPT
Developing Java Web Applications In Google App Engine
PPS
Advanced excel unit 01
PPTX
Final Year Project 1 Presentation
PPT
Google App Engine for Java
PPT
Multi user chat system using java
DOC
Report on online chatting
PDF
A project report on chat application
DOC
My Project Report Documentation with Abstract & Snapshots
PDF
Visual Design with Data
PDF
Build Features, Not Apps
Modernization in Eclipse
Japp klingemann reaction
Jar signing
Developing Java Web Applications In Google App Engine
Advanced excel unit 01
Final Year Project 1 Presentation
Google App Engine for Java
Multi user chat system using java
Report on online chatting
A project report on chat application
My Project Report Documentation with Abstract & Snapshots
Visual Design with Data
Build Features, Not Apps
Ad

Similar to Creating an executable jar file (20)

PPTX
OOP Lecture 23-JAR Files.pptx
PPTX
Unraveling the Jar File Format in Advanced java programming
PPTX
Untraveling the Jar File Format in Advanced java programming
PDF
Unraveling the Jar File Format in advanced Java programming
PDF
Unraveling-the-Jar-File-Format in advanced Java programming
PPT
20-packages-jar.ppt
PPT
Java package
PDF
02 basic java programming and operators
PDF
05 J2ME Wtk Command Line
PDF
Supplement2d netbeans6
PDF
Supplement2d netbeans6
PPTX
Java basics
DOCX
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
PPTX
chap 10 : Development (scjp/ocjp)
DOCX
asgmt01.classpathasgmt01.project asgmt01 .docx
PPT
Java ppts unit1
PDF
All experiment of java
PPTX
How to create a jar file using eclipse?
TXT
Readme
DOCX
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
OOP Lecture 23-JAR Files.pptx
Unraveling the Jar File Format in Advanced java programming
Untraveling the Jar File Format in Advanced java programming
Unraveling the Jar File Format in advanced Java programming
Unraveling-the-Jar-File-Format in advanced Java programming
20-packages-jar.ppt
Java package
02 basic java programming and operators
05 J2ME Wtk Command Line
Supplement2d netbeans6
Supplement2d netbeans6
Java basics
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
chap 10 : Development (scjp/ocjp)
asgmt01.classpathasgmt01.project asgmt01 .docx
Java ppts unit1
All experiment of java
How to create a jar file using eclipse?
Readme
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx

More from Ankush Srivastava (12)

PDF
Land Mine Detection and Image Processing
PDF
Comparative study of Salt & Pepper filters and Gaussian filters
PPT
Microprocessor
PPT
Data transferschemes
PPT
Dynamic RAM
PPT
Introduction to Computer Architecture
DOC
PPT
Introduction to Multimedia
PPT
Image processing SaltPepper Noise
PPTX
PPTX
Search Engine
Land Mine Detection and Image Processing
Comparative study of Salt & Pepper filters and Gaussian filters
Microprocessor
Data transferschemes
Dynamic RAM
Introduction to Computer Architecture
Introduction to Multimedia
Image processing SaltPepper Noise
Search Engine

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Machine Learning_overview_presentation.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
cuic standard and advanced reporting.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation theory and applications.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Machine Learning_overview_presentation.pptx
Assigned Numbers - 2025 - Bluetooth® Document
A comparative analysis of optical character recognition models for extracting...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
cuic standard and advanced reporting.pdf
sap open course for s4hana steps from ECC to s4
MIND Revenue Release Quarter 2 2025 Press Release
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Building Integrated photovoltaic BIPV_UPV.pdf
Approach and Philosophy of On baking technology
Big Data Technologies - Introduction.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation_ Review paper, used for researhc scholars
Programs and apps: productivity, graphics, security and other tools
Spectral efficient network and resource selection model in 5G networks
Encapsulation theory and applications.pdf

Creating an executable jar file

  • 1. Creating an Executable jar File In Java, it is common to combine several classes in one .jar ("java archive") file. Library classes are stored that way. Larger projects (such as the Case Study in the AP program) use jar files. You can create your own jar file combining several classes, too. jar files are created using the jar.exe utility program from JDK. You can make your jar file runnable by telling jar.exe which class has main. To do that, you first need to create a manifest file. A manifest is a one-line text file with a "Main-Class" directive. For example: Main-Class: DanceStudio This line must end with a newline. A jar file created with a main class manifest can be used both as a library and a runnable jar. If you use it as a library, you can edit and compile any of the classes included in the jar, and add it to your project. Then it will override the one in the jar file. You can create a manifest file in any text editor, or even by using the MS- DOS echo command. You can give your manifest file any name, but it’s better to use something standard, such as manifest.txt. Once you have a manifest and all your classes have been compiled, you need to run JDK’s jar.exeutility. It is located in the JDK’s bin folder, the same place where javac.exe and java.exe. are. jar.exe takes command-line arguments; if you run it without any arguments, it will display the usage information and examples. You need Cmywork> jar cvfm MyJarName.jar manifest.txt *.class cvfmmeans "create a jar; show verbose output; specify the output jar file name; specify the manifest file name." This is followed by the name you wish to give to your jar file, the name of your manifest file, and the list of .class files that you want included in the jar. *.class means all class files in the current directory. Below are the detailed steps for doing this in Command Prompt and in JCreator. Creating a jar File in JCreator
  • 2. You can configure a "tool" that will automate the jar creation process. You only need to do it once. 1. Click on Configure/Options. 2. Click on Tools in the left column. 3. Click New, and choose Create Jar file. 4. Click on the newly created entry Create Jar File in the left column under Tools. 5. Edit the middle line labeled Arguments: it should have cvfm $[PrjName].jar manifest.txt *.class 6. Click OK. Now set up a project for your program, create a manifest file manifest.txt or copy and edit an existing one. Place manifest.txt in the same folder where the .class files go. UnderView/Toolbars check the Tools toolbar. Click on the corresponding tool button or press Ctrl-1 (orCtrl-n if this is the n-th tool) to run the Create Jar File tool. With Windows Explorer, go to the jar file that you just created and double click on it to run. Creating a jar File in Command Prompt 1. Start Command Prompt. 2. Navigate to the folder that holds your class files: C:>cd mywork 3. Set path to include JDK’s bin. For example: C:mywork> path c:Program FilesJavajdk1.5.0_09bin;%path% 4. Compile your class(es): C:mywork> javac *.java 5. Create a manifest file: C:mywork> echo Main-Class: DanceStudio >manifest.txt 6. Create a jar file: C:mywork> jar cvfm DanceStudio.jar manifest.txt *.class
  • 3. 7. Test your jar: C:mywork> DanceStudio.jar