Creating an executable jar file is not that tough if it does not involve any external jars. Create a manifest file and mention the main class path in the manifest file. Place all the class files in a folder along with the manifest file and run the following command:
jar -cfm [name of the jar file] [name of the manifest]
Flags Description:
c: Create new archive
f: Specify the archive name
m: include manifest
* means include all the files in the current folder and all the sub folders.
The manifest file look something like this:
Main-Class: [name of the main class along with the package details]
Example
If your project has two files a.class and main.class. which are placed in a package(abc.def). Then the manifest would look like this(mainClass.mf):
___________________
Main-Class: abc.def.main
___________________
and the command to create an executable jar will be
jar -cfm test.jar mainClass.mf *
Everything works ok if you are not using any external jars but the problem arises when you have externals jar like you have used the logging component log4j. The manifest attribute Class-Path attribute in which you can mention the paths of the external jars, but i tried it for log4j but it didn't work it gives me error 'Logger Class Def Not Found'. I had created the following manifest for that (Keeping the above exapmle in mind)
__________________
Main-Class: abc.def.main
Class-Path: lib\log4j.jar
__________________
but this didn't worked.
Then i came across a work around for this, which is you create a jar file of your project class files without adding the extenal libaries ie. using the following same manifest:
___________________
Main-Class: abc.def.main
___________________
Place the created jar files along with the external jar files in another folder and then use the following manifest to create the final jar file.
____________________
Main-Class: abc.def.main
Class-Path: main\test.jar lib\log4j.jar
____________________
Notice that test.jar is the jar file of your actual project. the final jar created using the above manifest will work for you.
Search Your Question
Friday, May 30, 2008
Executable Jar File in JAVA. Interview quations
Subscribe to:
Post Comments (Atom)
Archives
-
▼
2008
(992)
-
▼
May
(474)
- Turtle 1.0 Interview question
- DotNet Framework & IIS installation order Intervi...
- Camps & Medicines are needed more than anything el...
- Executable Jar File in JAVA. Interview quations
- AJAX : Todays Buzz Interview question
- Executable Jar File in JAVA. Interview question
- AJAX : Todays Buzzword Interview question
- AJAX : Todays Buzzword Interview question
- AJAX : Todays Buzzword Interview question
- AJAX : Todays Buzzword Interview question
- What is .Resx file in Dot Net? Interview question
- How to use Microsoft Indexing Service? Interview q...
- Posting data to another ASPX Page Interview question
- Virtual Karma: Complete List of Web 2.0 Applicatio...
- Some Useful Web Links Interview question
- Home automation in the Netherlands Interview question
- Speed Up your web sites with HTTP Compression Inte...
- ASP.NET 2.0 Magic: Asynchronous Web Pages Intervie...
- RSS Puller in ASP Interview question
- ASP.NET: Interview Questions
- Java Interview Questions
- Java Interview Questions
- ASP.net Interview Questions
- PHP Interview Questions
- C Interview Questions
- C++ interview Questions
- ABAP Interview Questions
- SAP Interview Questions
- Resume Preparation Guidelines Interview question
- Salary Negotiation Interview question
- Points to remember Interview question
- Basic .NET Framework Interview question
- Software Testing Interview question
- SQL Server Interview question
- Database Interview question
- JAVA Interview Questions
- .NET Interview Questions
- SQL Server Interview Questions
- C++ Interview Questions
- Investment Management Interview Questions
- SAP-ABAP interview questions
- C Interview Questions Interview question
- Software Testing Interview Questions - Load Runner...
- Software Testing Interview Questions - Win Runner
- Software Testing Interview Questions - Manual
- ASP Interview Questions
- Oracle Interview Questions - Part 1
- VB Interview Questions
- Java Interview Questions
- J2EE Interview Questions
- C Interview Questions
- .net Interview Questions
- Java Interview Questions
- Accounting Interview Questions
- Behavioral Interview Questions Interview question
- Finance Interview Questions Interview question
- Technical &Quantitative Interview Questions Inter...
- ABAP / 4 Interview Questions Interview question
- HR Interview Questions Interview question
- C interview Questions Interview question
- Interview Concepts Interview question
- Oracle Interview Questions - Part 2 Interview que...
- Oracle Interview Questions - Part 3 Interview qu...
- Oracle Interview Questions - Part 4 Interview que...
- Oracle Interview Questions - Part 6 Interview que...
- Oracle Interview Questions - Part 7 Interview que...
- PHP Interview Questions - Part 1 Interview question
- Oracle Interview Questions - Part 8 Interview que...
- Oracle Interview Questions - Part 9 Interview que...
- Oracle Interview Questions - Part 10 Interview qu...
- Oracle Interview Questions - Part 11 Interview qu...
- Oracle Interview Questions - Part 12 Interview qu...
- Interview Tips Interview question
- PHP Interview Questions - Part 2 Interview question
- Dot Net Interview Questions - Part 1 Interview qu...
- J2ME Interview Questions Interview question
- CCNA Interview Questions Interview question
- Dot Net Interview Questions - Part 2 Interview qu...
- Dot Net Interview Questions - Part 4 Interview qu...
- Dot Net Interview Questions - Part 5 Interview qu...
- Dot Net Interview Questions - Part 6 Interview qu...
- Dot Net Interview Questions - Part 7 Interview qu...
- Dot Net Interview Questions - Part 8 Interview qu...
- Dot Net Interview Questions - Part 9 Interview qu...
- Dot Net Interview Questions - Part 10 Interview q...
- Dot Net Interview Questions - Part 11 Interview q...
- Dot Net Interview Questions - Part 12 Interview q...
- Dot Net Interview Questions - Part 14 Interview q...
- Dot Net Interview Questions - Part 15 Interview q...
- PHP Interview Questions - Part 3 Interview question
- PHP Interview Questions - Part 1 Interview question
- Oracle Interview Questions - Part 8 Interview ques...
- Oracle Interview Questions - Part 9 Interview ques...
- Oracle Interview Questions - Part 10 Interview que...
- Oracle Interview Questions - Part 11 Interview que...
- Oracle Interview Questions - Part 12 Interview qu...
- Interview Tips Interview question
- PHP Interview Questions - Part 2 Interview question
- Dot Net Interview Questions - Part 1 Interview que...
- J2ME Interview Questions Interview question
-
▼
May
(474)
No comments:
Post a Comment