Home | Login | Blog | Forum | Download | RSS Feed | Ajax | Hello-World | J2EE | BPM | EJB | FileNet | Hibernate | ORM | IBM | ILOG | Interview | FAQs |

Java | Apache | JVM | Others | BRMS | Oracle | Pega | SOA | Sun-Certification | Web-Service | websphere | XML |
 

JAVA DEVELOPER SITE - COMPLETE JAVA TUTORIALS

How to Create a Jar File in Java Using Eclipse IDE


Share
 
 

Useful Java Links


       


Let us see how to create a JAR file using Java’s jar command as well as using Eclipse IDE. The JAR file format is based on the popular ZIP file format. Usually these file are used for archiving and distribution the files and implementing various libraries, components and plug-ins in java applications. Compiler and JVMs (Java Virtual Machine) can understand and implement these formats for java application.

JAR files are the output of the Java Archive Tool. The Java Archive Tool is a program that is part of the Java Standard Edition Software Development Kit.). Before using a jar command we need to set the classpath. . Generally the path is where the OS looks to run programs. jar files are created using the jar.exe utility program from JDK. We can make our jar file runnable .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

 

A jar file created with a main class manifest can be used both as a library and a runnable jar. See the following command to create executable jar file

jar cvfm MyJarName.jar manifest.txt *.class

cvfm means "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.

 

Following are the steps to create a jar file from the command prompt

Ø  Start Command Prompt.

Ø  Navigate to the folder that holds your class files:

Ø  C:\>cd \mywork

Ø  Set path to include JDK’s bin.  For example:

Ø  C:\mywork> path c:\Program Files\Java\jdk1.5.0_09\bin;%path%

Ø  Compile your class(es):

Ø  C:\mywork> javac *.java

Ø  Create a manifest file: 

Ø  C:\mywork> echo Main-Class: DanceStudio >manifest.txt

Ø  Create a jar file:

Ø  C:\mywork> jar cvfm DanceStudio.jar manifest.txt *.class

Ø  Test your jar:

Ø  C:\mywork> DanceStudio.jar

To create a  JAR file in the Eclipse workbench:

  1. In the Package Explorer, we can optionally pre-select one or more Java elements to export. These will be open the wizard page.
  2. Either from the context menu or from the menu bar's File menu, select Export.
  3. Expand the Java node in the wizard page and select JAR file. Click Next.
  4. In the JAR File Specification page, select the resources that we want to export in the Select the resources to export field.
  5. Select the appropriate checkbox to specify whether we want to Export generated class files and resources or Export Java source files and resources. Note: Selected resources are exported in both cases.
  6. In the Select the export destination field, either type or click Browse to select a location for the JAR file.
  7. Select or clear the Compress the contents of the JAR file checkbox.
  8. Select or clear the Overwrite existing files without warning checkbox. If we clear this checkbox, then we will be prompted to confirm the replacement of each file that will be overwritten.
  9. Note: The overwrite option is applied when writing the JAR file, the JAR description, and the manifest file.
  10. Now we have two options:
  11. Click Finish to create the JAR file immediately.
  12. Click Next to use the JAR Packaging Options page to set advanced options, create a JAR description, or change the default manifest.
  13. If we want to save the JAR file description, select the Save the description of this JAR in the workspace checkbox. A JAR file description can be used to regenerate a JAR file without using the wizard.
  14. The compiler is able to generate CLASS files even when source contains errors. We have the option to exclude CLASS (but not source) files with compile errors. These files will be reported at the end, if reporting is enabled.
  15. We can choose to exclude CLASS (but not source) files that have compile warnings. These files will be reported at the end.
    Note: This option does not automatically exclude class files with compile errors.
  16. We can choose to include the source folder path by selecting the Create source folder structure checkbox.
  17.  Select the Build projects if not built automatically checkbox if you want the export to perform a build before creating the JAR file.
  18. Click Finish to create the JAR file immediately or Next if we want to change the default manifest.
  19. If it is not already selected, click the Generate the manifest file button.
  20. We can now choose to save the manifest in the workbench. This will save the manifest for later use. Click Save the manifest in the workspace, then click Browse next to the Manifest file field to specify a path and file name for the manifest.
  21. If we decided to save the manifest file in the previous step and you chose to save the JAR description on the previous wizard page, then you can choose to reuse it in the JAR description (by selecting the Reuse and save the manifest in the workspace checkbox). This means that the saved file will be used when the JAR file is recreated from the JAR description.This option is useful if you want to modify or replace the manifest file before recreating the JAR file from the description.
  22. We can choose to seal the JAR and optionally exclude some packages from being sealed or specify a list with sealed packages. By default, nothing is sealed.
  23. Click the Browse button next to the Main class field to specify the entry point for our applications.
    Note: If our class is not in the list, then we forgot to select it at the beginning.   Click Finish. This will create the JAR, and optionally a JAR description and a manifest file.



Download Latest Java/J2EE eBooks, SCJP Dumps, SCWCD Dumps, Pega Tutorial, IBM WebSphere BPM tutorials and many more


If you need any urgent assistance on how-to-create-jar-file-in-java-using-eclipse, kindly email your requirement to us at : info@javagenious.com or Contact-an-Expert. Our experts will try their best to solve your problem.

You can also subscribe to our newsletters on how-to-create-jar-file-in-java-using-eclipse, to receive updates on how-to-create-jar-file-in-java-using-eclipse,via email.Enter you email below:

Enter your email address:

Delivered by FeedBurner



Keyword Tags: how-to-create-jar-file-in-java-using-eclipse tutorial,how-to-create-jar-file-in-java-using-eclipse in java,Concepts of how-to-create-jar-file-in-java-using-eclipse,Java,J2EE,Interview Questions,how-to-create-jar-file-in-java-using-eclipse Examples


Comments:


Post Your Comment:

*

Yes, I would like to recieve email notifications on my reply.

Popular Posts:

 
Popular Downloads

SCJP 1.6 Dumps
JSP Interview Questions
Struts Interview Questions
Hibernate Interview Questions
SCWCD Dumps
SCBCD Dumps

Java/J2EE Tutorial
JMS Tutorials
seam richfaces tutorial
richfaces live demo
jquery example demo
JQuery Tutorial and Source Code
JSF Tutorial
XSL Tutorial
J2EE JMS
CORBA Applications
Java CERTIFICATION
SCJP 1.5
SCJP 1.6
SCWCD 1.5
SCBCD
Mis
Ajax autosuggest autocomplete from database
Struts forms and validation with webflow
Java Apache POI Examples
JDBC Tutorial
Oracle 9i & 10g
MYSQL Tutorial
php Tutorial
JQuery Examples
Upload Java File
JAXB Examples
PL-SQL Tutorial
Dojo AJAX
EJB Examples
Java IDE
Eclipse
NetBeans
IBM Rational Weblogic Workshop
Downloads
SCJP 1.6 Dumps
SCJP 1.5 DUMP
SCJP Material
SCWCD
Java Security
SCBCD Dumps
External Links
SUN Java
JOracle
IBM
PHP Certification
Technical Interview Questions
Amazon Interview Questions
Google Interview Questions
Microsoft Interview Questions
IBM Interview Questions
Yahoo Interview Questions
All Tutorials
php mysql tutorial
SCJP 1.5/1.6
SCWCD 1.5/1.6
Polymorphism
Thread Tutorial
Generics & Exceptions
Spring Struts Hibernate
Java Collections
MAP
SET
LIST
VECTOR
Advanced Java
Stateless Session Bean
Introduction to EJB
Stateful Session Bean
Java Design Patterns
HOME | FORUM | ABOUT | BLOGS | CONTACT-US