Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  yordan : (14 April 2014 - 05:28 PM) By The Way, This Could Be An Interesting Subject For A Topic, What About Posting This Question? Let's See If Other People Have The Same Feeling Concerning Bootlists!
@  yordan : (13 April 2014 - 09:36 AM) Boot Order : Cd, [Usb,] Hard Drive :D
@  yordan : (11 April 2014 - 07:23 PM) I Simply Let The Bios Do That
@  Ritesh : (11 April 2014 - 10:23 AM) Is It Possible To Launch Fedora Live Cd Or Installation Disk From Hard Drive On Windows Platform Using Grub Mbr File.
@  Ritesh : (11 April 2014 - 10:21 AM) No U Are Not.. Btw.. I Have Question For You.
@  yordan : (10 April 2014 - 08:02 AM) You Are Partially Right.
I Was Not.
Nevertheless, I Am Again :)
@  Ritesh : (09 April 2014 - 07:33 PM) :P
@  Ritesh : (09 April 2014 - 07:33 PM) I Think U R Not..
@  yordan : (09 April 2014 - 09:28 AM) I'm The Master Of The Shoutbox!
@  yordan : (05 April 2014 - 10:32 PM) He-He
@  Ritesh : (04 April 2014 - 06:59 PM) Ha Ha Ha ....
@  yordan : (04 April 2014 - 11:15 AM) Welcome Back, Starscream!
@  yordan : (03 April 2014 - 02:31 PM) And I Hope That He Will Come Back Soon :)
@  yordan : (01 April 2014 - 02:53 PM) Nice, Ritesh Came, I'm Not Home Alone Today.
@  Ritesh : (01 April 2014 - 08:51 AM) Oh!!! Poor Dear Yordan..
@  yordan : (31 March 2014 - 10:02 AM) I'm A Poor Lonesome Cow-Boy
@  yordan : (27 March 2014 - 02:22 PM) He Is Unpatient Due To His Patients!
@  Ritesh : (27 March 2014 - 10:46 AM) :(
@  Ritesh : (27 March 2014 - 10:46 AM) He Is Busy With His Patients.
@  yordan : (26 March 2014 - 08:12 PM) Ahsani, Where Are You?

Photo
- - - - -

Creating Executable Jar Files


31 replies to this topic

#1 vicky99

vicky99

    Member [ Level 2 ]

  • Members
  • 54 posts

Posted 28 May 2006 - 11:56 AM

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.

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
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.

#2 Guest_FeedBacker_*

Guest_FeedBacker_*
  • Guests

Posted 10 October 2007 - 04:33 AM

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

-Tanveer I. Shaikh

#3 java-area

java-area

    Member [ Level 1 ]

  • [HOSTED]
  • 47 posts

Posted 04 February 2008 - 03:57 AM

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).

Edited by java-area, 04 February 2008 - 03:59 AM.


#4 Guest_FeedBacker_*

Guest_FeedBacker_*
  • Guests

Posted 17 March 2008 - 08:26 AM

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

#5 java-area

java-area

    Member [ Level 1 ]

  • [HOSTED]
  • 47 posts

Posted 25 March 2008 - 03:35 PM

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


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/...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.

#6 Guest_FeedBacker_*

Guest_FeedBacker_*
  • Guests

Posted 31 March 2008 - 05:49 AM

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

#7 Guest_FeedBacker_*

Guest_FeedBacker_*
  • Guests

Posted 29 May 2008 - 12:39 PM

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

#8 niks

niks

    Newbie [ Level 1 ]

  • Members
  • 1 posts

Posted 15 July 2008 - 05:56 AM

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,



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.

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
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.

Attached Files



#9 toby

toby

    Super Member

  • Members
  • 611 posts

Posted 15 July 2008 - 01:34 PM

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

#10 Guest_iGuest-arti_*

Guest_iGuest-arti_*
  • Guests

Posted 29 July 2008 - 10:26 AM

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

#11 Guest_(G)jeetu_*

Guest_(G)jeetu_*
  • Guests

Posted 09 January 2009 - 08:12 AM

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..



#12 Guest_(G)Author Name - e.g. John, Mike_*

Guest_(G)Author Name - e.g. John, Mike_*
  • Guests

Posted 11 March 2009 - 05:51 AM

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 ?



#13 Guest_(G)prameela_*

Guest_(G)prameela_*
  • Guests

Posted 08 April 2009 - 06:52 AM

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

 



#14 Guest_(G)Abhi_*

Guest_(G)Abhi_*
  • Guests

Posted 21 July 2009 - 03:54 PM

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

#15 Guest_(G)sal_*

Guest_(G)sal_*
  • Guests

Posted 14 October 2009 - 07:41 AM

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



#16 Guest_(G)shashikant verma_*

Guest_(G)shashikant verma_*
  • Guests

Posted 11 November 2009 - 06:00 AM

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

 

 



#17 starscream

starscream

    Super Member

  • Members
  • 896 posts
  • Gender:Male
  • Location:Land of Shadows
  • myCENTs:84.35

Posted 11 November 2009 - 01:18 PM

@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.

#18 Guest_(G)sagar salunkhe_*

Guest_(G)sagar salunkhe_*
  • Guests

Posted 16 November 2009 - 06:54 AM

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

 



#19 starscream

starscream

    Super Member

  • Members
  • 896 posts
  • Gender:Male
  • Location:Land of Shadows
  • myCENTs:84.35

Posted 16 November 2009 - 03:48 PM

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.

#20 Guest_(G)engkoment_*

Guest_(G)engkoment_*
  • Guests

Posted 21 December 2009 - 08:46 AM

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

 





Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users