Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Creating Executable Jar Files
vicky99
post May 28 2006, 11:56 AM
Post #1


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 54
Joined: 28-May 06
Member No.: 13,691



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 (cool.gif 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.
Go to the top of the page
 
+Quote Post
Feedbacker
post Oct 10 2007, 04:33 AM
Post #2


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869





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

-Tanveer I. Shaikh
Go to the top of the page
 
+Quote Post
java-area
post Feb 4 2008, 03:57 AM
Post #3


Member [ Level 1 ]
Group Icon

Group: [HOSTED]
Posts: 47
Joined: 4-February 08
Member No.: 28,119



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

This post has been edited by java-area: Feb 4 2008, 03:59 AM
Go to the top of the page
 
+Quote Post
Feedbacker
post Mar 17 2008, 08:26 AM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



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
Go to the top of the page
 
+Quote Post
java-area
post Mar 25 2008, 03:35 PM
Post #5


Member [ Level 1 ]
Group Icon

Group: [HOSTED]
Posts: 47
Joined: 4-February 08
Member No.: 28,119



QUOTE(FeedBacker @ Mar 17 2008, 04: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


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.




Go to the top of the page
 
+Quote Post
Feedbacker
post Mar 31 2008, 05:49 AM
Post #6


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



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: lib\jar1.Jar lib\jar2.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
Go to the top of the page
 
+Quote Post
Feedbacker
post May 29 2008, 12:39 PM
Post #7


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



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 Files\JMF2.1.1e\lib, 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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Converting Flash Files To Gif(6)
  2. How To Hide Your Files In XP(17)
  3. Creating A Game In Rpg Maker 2000/2003(17)
  4. Network Places: Alternative To Ftp On Windows(10)
  5. How To Transfer Files From One Computer To Another(13)
  6. Creating You Own Game In RPG Maker 2000/2003(12)
  7. How Do I Create And Write To Files?(4)
  8. VB.NET: Howto Add And Delete Files(8)
  9. How To Play *.rm Files With Media Player(11)
  10. Permission Denied In Creating A Directory(6)
  11. Help Me: Need To Transfer Files From Old Computer(18)
  12. Switch Network Settings With Batch Files(16)
  13. Creating Irc Chat Room...(9)
  14. Creating Your Own Simple But Effective Site(26)
  15. Creating New Process Under Alternate Credentials (createprocessasuser)(5)
  1. Help Creating A Browser-based Rpg(5)
  2. Software To Concatenate Mp3 Files(8)
  3. Creating Interactive Pdf Documents(2)
  4. Uploading More Than 30 Files In Less Than 10 Clicks?(5)
  5. Creating Your First Application(1)
  6. Help Me Creating My Text Based Game.(2)
  7. Creating Bootable Cds(1)
  8. Magic Quotes And $_files(3)
  9. Friends Can't Start The Exe Files I Send :((3)
  10. Creating Links With Quotes (")(2)
  11. 3d Game Creating Thing(1)
  12. Need Some Help/advice On Lost Files.(8)
  13. Need Some Help/advice On How To Restore Lost Files(3)


 



- Lo-Fi Version Time is now: 6th July 2008 - 06:54 AM