Loading...


bookmark - Creating Executable Jar Files

Creating Executable Jar Files

 
 Discussion by vicky99 with 31 Replies.
 Last Update: November 13, 2011, 7:17 am ( View Rated (3) ) (View Latest)
Page 1 of 2 pages.
bookmark - Creating Executable Jar Files  
Quickly Post to Creating Executable Jar Files  w/o signup Share Info about Creating Executable Jar Files  using Facebook, Twitter etc. email your friend about Creating Executable Jar Files Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print


Dear Friends
Today I will show you how to create an executable jar file. I do not know whether this topic is introduced by any other member. Using this method one can build graphical user interface program with java which will behave similar to Executable files i.e., the program can be started with double clicks. It is an easy alternative. Otherwise to run a java program one has to run it through comand prompt(in windows) using java command or by creating java executalbes which are very difficult to make. So lets begin:

Frist of all, we will create a simple java application using java foundation class popularly known as java Swing. Let the file name be JarExample.

CODE


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JarExample {

private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);

JFrame frame = new JFrame("Window");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(175, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}



Now compile the java file. JDK will produce two class files namely (a)JarExample.class (:D JarExample$1.class.
All the years we have been doing this.Your question might be what new? Its coming.
Now we will create a Manifest File. If you have done java beans then you are quite familiar with the term.
Let write our Manifest File:-
The name of the file is :- jex.mf

CODE


Manifest-Version: 1.0
Main-Class: JarExample

We are now ready to create our JAR file.
create a folder, keep the class files (JarExample.class,JarExample$1.class) and the manifest file in that folder.
Now open command prompt. Say for example your folder name is jar and you have kept it in C DRIVE. Now change directory using CD jar command.
Now we will create jar file using following command.
c:\jar>jar cfm jarex.jar jex.mf *.class
It will create jarex.jar .
I wish you will be able to create jar file using this method. If any problem occur feel free to ask me or you have any suggestion please tell me.

   Sun May 28, 2006    Reply         

Query : How can I set/change an Icon for my exe jar?

-Tanveer I. Shaikh

   Tue Oct 9, 2007    Reply         

vicky99, cool!

The key point of creating executable JAR-file is creating manifest file, which has a link to the executable class (the class with a static public method Main).

   Sun Feb 3, 2008    Reply         


Creating executable jar file in java
Creating Executable Jar Files

I created the jar file as per your instruction, but it is not executing by showing the error " FAILED TO LOAD MAIN-CLASS" MANIFEST ATTRIBUTE FROM THE RESPECTIVE JAR FILE (Eg. My jar file name is test so it is showing c:test.Jar). What might be the problem . Please help me out in this regard

Pradeep

-reply by pratheep kumar s

   Mon Mar 17, 2008    Reply         

QUOTE (FeedBacker)

Creating executable jar file in java

Creating Executable Jar Files
I created the jar file as per your instruction, but it is not executing by showing the error " FAILED TO LOAD MAIN-CLASS" MANIFEST ATTRIBUTE FROM THE RESPECTIVE JAR FILE (Eg. My jar file name is test so it is showing c:test.Jar). What might be the problem . Please help me out in this regard

Pradeep

-reply by pratheep kumar s
Link: view Post: 120601


It works well! But there is a small truck.
Lets look at Sun's tutorial:
"Note : The contents of the manifest must be encoded in UTF8"
(http://java.sun.com/docs/books/tutorial/de...jar/modman.html)

I tryed to create the manifest file (in our case - jex.mf) using different text editors and I had different results!!!
When jar utility program understand the context of jex.mf, it includes the string "Main-Class: JarExample" into the new manifest file, which can be found in executable jar file.
But sometimes Jar utility does not understand the text format of manifest file (jex.mf) -
seems, it depends on the text editor, used for creating jex.mf.

For example, I have created a new text file in Wordpad, copied the string "Main-Class: JarExample" into it and saved as jex.mf.
Jar utility has successfully created executable .jar with manifest file, containing "Main-Class: JarExample"
But I am not pretty sure about other text editors and formats, used for creating jex.mf.
So, you need to double check manifest file in executable .jar -
If it does NOT contain the string "Main-Class: JarExample", put it manually.

   Tue Mar 25, 2008    Reply         

creating jar files with external jar files
Creating Executable Jar Files

Replying to java-areaReplying to java-area
Hi,
I want create a jar file that contain other external jar files.

My Manifest file manifest.Mf looks like:

Main-Class: MainClass
Class-Path: libjar1.Jar libjar2.Jar lib jar3.Jar...


I used the command >> jar cfm myJar.Jar manifest.Mf *

The jar myJar.Jar is working only in the location where I created that jar file.When I tried to move that jar file into another loacation it displaying an exception reagarding the external jar files..If I copy that lib folder having the external jar files into that location it will execute..

Thanks in advance.
Rajisp




-reply by rajisp

   Sun Mar 30, 2008    Reply         


JMF doesn
Creating Executable Jar Files


I have a problem with JMF .I m working on capturing of image from webcam. When I build path of JMF lib files by adding �Add Jar � from eclipse IDE , my application run but capture function of webcam doesn�t work means it doesn�t get path of JMF lib file . But if JMF lib file added directly from
C:Program FilesJMF2.1.1elib, it captures image.
I created executable jar file with the help of One jar file.But my executable jar file doesn�t work with JMF . Can anyone help how to set path of JMF lib file so that it capture image from executable jar file.


Thanks a lot in advance


-question by Shweta

   Thu May 29, 2008    Reply         

Hi,
I have created the jar file in the way described by you, but i ma not able to execute it by double clicking it. I get the following screen(winrar screen).
Kindly help as his is really urgent. And i will be greatful if you can through some light on running this same .jar file on windows mobile.

Thanks and Regards,



QUOTE (vicky99)

Dear Friends
Today I will show you how to create an executable jar file. I do not know whether this topic is introduced by any other member. Using this method one can build graphical user interface program with java which will behave similar to Executable files i.e., the program can be started with double clicks. It is an easy alternative. Otherwise to run a java program one has to run it through comand prompt(in windows) using java command or by creating java executalbes which are very difficult to make. So lets begin:

Frist of all, we will create a simple java application using java foundation class popularly known as java Swing. Let the file name be JarExample.

CODE

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JarExample {

private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);

JFrame frame = new JFrame("Window");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(175, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}


Now compile the java file. JDK will produce two class files namely (a)JarExample.class (:) JarExample$1.class.
All the years we have been doing this.Your question might be what new? Its coming.
Now we will create a Manifest File. If you have done java beans then you are quite familiar with the term.
Let write our Manifest File:-
The name of the file is :- jex.mf

CODE

Manifest-Version: 1.0
Main-Class: JarExample

We are now ready to create our JAR file.
create a folder, keep the class files (JarExample.class,JarExample$1.class) and the manifest file in that folder.
Now open command prompt. Say for example your folder name is jar and you have kept it in C DRIVE. Now change directory using CD jar command.
Now we will create jar file using following command.
c:\jar>jar cfm jarex.jar jex.mf *.class
It will create jarex.jar .
I wish you will be able to create jar file using this method. If any problem occur feel free to ask me or you have any suggestion please tell me.
Link: view Post: 79387

   Mon Jul 14, 2008    Reply         

Can I make an executable from a website java archive(.jar)?

   Tue Jul 15, 2008    Reply         

creating a jar file
Creating Executable Jar Files

When I create ajar file it gives me a

Java.Io.IOException: invalid header field
at java.Util.Jar.Attributes.Read(Attributes.Java:393)
at java.Util.Jar.Manifest.Read(Manifest.Java:167)
at java.Util.Jar.Manifest.<init>(Manifest.Java:52)
at sun.Tools.Jar.Main.Run(Main.Java:123)
at sun.Tools.Jar.Main.Main(Main.Java:90)
What does this mean.Please help me out.



-question by arti

   Tue Jul 29, 2008    Reply         

create mobile jar file - cannot run commandCreating Executable Jar Files

I cannot run the following line or command;C:jar>jar cfm jarex.Jar jex.Mf *.ClassI have created jar folder contaning the 2 class files and a manifest file. But cannot run the above command it says..'jar' is not recognised as an external or internal command, operable program or batch file..

   Fri Jan 9, 2009    Reply         

how to build an executable jar eclipseCreating Executable Jar Files

very nice and eazy undarstandable.Thank you very much. But am experiencing a problem while creating executable jar where the main class is defined in a package.Is there any additional settings to be done ?

   Tue Mar 10, 2009    Reply         

creating jar fileCreating Executable Jar Files

create jar file using these statements in command promt:

echo Main-Class: name of the main program>manifest.Txt

jar cvfm Hello.Jar manifest.Txt *.Class

After executing this "Hello.Jar" file will be created.

Then run the jar file in comand promt  using:

java -jar <name of the jar>

or

double click in jar file.

 

-reply by prameela

 

   Tue Apr 7, 2009    Reply         

additional Meta-Inf in the jar file contentsCreating Executable Jar Files

Hi!

 I followed  Vicky99's as well as Prameela's reply to create a jar file. However when I looked at the contents of the jar file I find that there are the following files

META-INF/

META-INF/MANIFEST.MF

Authenticator.Class

Here Manifest.Mf is the manifest file I created using Prameela's reply and Authenticator is a class file I created, which to be sure runs perfectly fine if executed using the standard JDK method. 

I believe that the first file META-INF shouldn't be there. Any suggestions as to what I should do??

Thanks

-question by Abhi

   Tue Jul 21, 2009    Reply         

help to add the mysqldriverCreating Executable Jar Files

Hi friends,

I had developed an application for a video shop in netbeans in which the there were English,korean movies etc section .If the user choose the english  the list of dvd,cd available will be loaded on the drop down and the list of customers or a text box to enter the new customer who want to take the dvd or cd for rent,the application was mainly developed on swing,and the data that stores is in the ms access.And there are lot of other features also for the application.

After the completion of the project the I  build the application,and a jar file had created in the dist folder with the lib folder.

But my problem is that how I will give the project to the customer ie the customer is a less knowledge in computer so I had to give this application in a setup format so that if he clicked the setup it will automatically install the software with the whole database connection and database ,and if any day he uninstalled the s/w the data that store initially  not be remove from the computer,I had gone through install4j s/w to make the setup but I not  success in developing the s/w.How can I add the ms access or the mysql driver so that the user click on the setup it will install the software+the database and the connection has to done.

Or the jar file that on double clicking may work properly as per the requirement.

Will any body please help me how to do the above thing or any website that form the tutorial to do,

Thank in advance

   Wed Oct 14, 2009    Reply         

jar file Creating Executable Jar Files

Replying to vicky99Hi..I have done all the step as per done by u. But my jar file is not opening when I double click on the jar file . Pls suggest me right step for it.Waiting for reply.

ThanksShashikant

 

 

   Tue Nov 10, 2009    Reply         

@Shashikant, why don't you use jar2exe ? It is one good way of using it with jar files. With jar files you can use jar2exe to convert your files to exe. There are many other installer and software that can create executable or installer for jar files. Check google.

   Wed Nov 11, 2009    Reply         

error problem in main classCreating Executable Jar Files

your code creates a jar file but it gives a error "Failed to load manifest attribute for  jarex.Jar file" 

-reply by sagar salunkhe

 

   Sun Nov 15, 2009    Reply         

QUOTE

your code creates a jar file but it gives a error "Failed to load manifest attribute for jarex.Jar file"


Why don't you use jar2exe ? That way of using to convert the jar file to exe is much better and performance is not affected as well. You need to try that. If it is not working then post here. I'll try and solve it.

   Mon Nov 16, 2009    Reply         

problem solvedCreating Executable Jar FilesIn your jex.Mf:Manifest-Version: 1.0Main-Class: JarExampleNote: make sure you type a carriage return after this line; some windowsSystems need it and will report a "Failed to load Main-Class manifestAttribute" error.

source:

http://csdl.Ics.Hawaii.Edu/~johnson/613f99/modules/04/jar-files.Html

-reply by engkoment

 

   Mon Dec 21, 2009    Reply         

got error while running a jar fileCreating Executable Jar Files

I got an error while executing the jar file and the error is as follow;

"failed to load Main-class manifest attribute from E:/my games/game.Jar "

pls help me in this regard. How can I rectify this error??? 

-reply by raju garu

 

   Sun Jan 3, 2010    Reply         

Notice to all members, must and should seeCreating Executable Jar Files

Everybody must be noticing that the neobux ads load very slowly and sometimes they do not load at all as mentioned by some members. There is a little trick which will certainly make the neobux ads to load fast. Many of you might be knowing it but for those who do not know it they can try it and make the ads load faster. Here is the trick:After you click on the ad, when the ad page opens, scroll down to the bottom of the ad page and click on some link on that page and the ad will start to load immediately.I.E the timer will start. If it does not start, then once again click on some other link in that page and this time the ad will definitely start to loadHttp://doiop.Com/vickydadaI am NOT a big fan of PTC programs, especially ones that use AlertPay and especially the ones that take months to payout. But I have to admit that I am extremely impressed with NeoBux.I love NeoBux, because you get paid just by browsing our sponsor's ads.What you get as a member:Earn up to <% CONTENT %>.02 (2 cents) per click.Earn up to <% CONTENT %>.02 (2 cents) for every ad your referrals click.Earn up to 10% of every purchase made here by your direct referrals.Access detailed statistics of your clicks, earnings and even of your referral's clicks and activities.Payment via Alertpay and PayPal!Pay and receive instantly (in seconds)!Neobux is the best PTC site out there with more than 900000 members and paid almsot 0,000.00 and growing.Imagine you have 2000 rented referrals - that’s 00/month..Not bad, huh? Gaining referrals need a little patience though.

 

   Sun Jun 20, 2010    Reply         

answer to Failed to load manifest attribute for jarex.Jar Creating Executable Jar Files

open the jar file with the winRAR

then ope the mainfest folder andd file in it with noepad

if the code is corrupted edit it and save 

-reply by mzalih

 

   Sun Sep 26, 2010    Reply         

Error: Failed to load Main-Class manifest attribute from packEx.jarCreating Executable Jar Files

We have the following project directory of classes and source.

1 Classes >> com.Headfirstjava.PackageExercise.Class. Source >>com.Headfirstjava.PackageExercise.Java

2. A text file of manifest.Txt in notepad has a single line.

Main-Class: com.Headfirstjava.PackageExercise and save this text file as manifest.Txt. We have put this manifest.Txt file  in Classes folder.

3. We run the jar tool to create JAR File D:ProjectClasses> jar cf packEx.Jar manifest.Txt com

4. Running(executing) the JAR >> java -jar packEx.Jar. Error : Failed to load ...From packEx.Jar.

Let us view the contents of jar file: jar -tf packEx.Jar >> META - INF/MANIFEST.MF manifest.Txt com/headfirstjava/PackageExercise.Class

Let us extract all the contents of a jar file: jar -xf packEx.Jar. Kindly, note that packEx.Jar is not extracting.Is it the reason for getting error - " Failed to load


from packEx.Jar". Can anybody fix it?

-question by Arindam Biswas

 

   Sun Oct 3, 2010    Reply         

pagination integration with existing projectCreating Executable Jar Files

Hi

I created a pagination code using java swing. I need to integrate it with my existing code. That is my retail project. Here now all the data will be in one page. I need to change it as pagination. But I did separate app pagination. So now I need to integrate it. But I don't know how to do. Pls can any one tell me about this.

-reply by kumar

 

   Fri Jan 21, 2011    Reply         

How to create setup for a java project?Creating Executable Jar Files

R/Sir

I have already created a runnable jar file using manifiest file but I wanna ask you, How to create setup for a java project?

-question by Ramesh

   Fri Apr 1, 2011    Reply         

Didnt Work Creating Executable Jar Files

I follwoed that procedure.Jar file is created.ButDid not excute that jar file.Error: "failed to load main-class manifest attribute from jar"Please give any other options...

-reply by Warma

   Fri Jun 3, 2011    Reply         

how to create a single exe file for my project?Creating Executable Jar Files

Replying to vicky99Hii!! I have created a project on hospital managment...In java language...Now the problem is that ...My project contains 25 files including (java class files,java source files and 3 jpeg file)...And now I want to make a single executable file (exe file) for the complete project ...Like other software have...Pllzz help me...As soon as possible... Thnk u...

-question by Varun Chauhan

   Sat Sep 3, 2011    Reply         

eclipse executable jar problemCreating Executable Jar Files

I am working on a simple mobile game in java.Finally, I am done with the running code in eclipse, but unable to deploy it in an executable jar file, since my game contains two files first.Java(extends MIDlet) and second.Java(GameCanvas) and none of them having "main" in it, all are inherited abstract methods...I have tried various ways to create the same but each time stuck at manifest entries where main class is to be defined. If I try to do this using eclipse export wizard, I am not able to find any launch configuration, the dropdown list comes empty...Somebody help!

-question by Neelabh

   Fri Sep 2, 2011    Reply         

about create executable Jar fileCreating Executable Jar FilesReplying to vicky99I have successfully created a jar file.But when I open this .Jar then a msg comes--" A JAVA exception has occurred ".-question by Aayush

   Tue Oct 18, 2011    Reply         

Quickly Post to Creating Executable Jar Files  w/o signup Share Info about Creating Executable Jar Files  using Facebook, Twitter etc. email your friend about Creating Executable Jar Files Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print


Similar Topics:

How Do I Create And Write To Files?

Hi, Can someone please tell me how to create files and write to them in PHP. I just want to create a simple file containing text, and then be able to read it or update it. Thanks Alfie ...more

   11-May-2005    Reply         

Request Astahost Hosting And Upload...

...more

   20-Jun-2005    Reply         

Creating New Process Under Alternat...

I am having quite the time spawning a process under a different user context. My preferred method involves using the Windows API functions LogonUser() and CreateProcessAsUser() but I have not figured out a way to overcome several error messages. I also have the particular problem of running my pro ...more

   10-Jul-2006    Reply         

Java Phone Book A console base java phone book program   Java Phone Book A console base java phone book program (5) (20) How To Create Exe File In Java?   How To Create Exe File In Java?