How to Create Executable JAR FILE?
Example:
create on java program with main method.
import java.awt.*;
import java.awt.event.*;
public class JarDemo
{
public static void main(String args[]){
Frame f=new Frame();
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){
for(int i=0;i<=10;i++)
System.out.println("I am Closing Window"+i);
System.exit(0);
}
});
f.add(new Label(" i can create Executable jar file");
f.setSize(500,500);
f.setVisible(true);
}
}
javac JarDemo.java
when we run this command we get two .class files JarDemo.class and JarDemo$1.class[Anonymous Innerclass]
so for creating jar file using the above .class fils we need to decide which class would be the main class. for this we need to write one manifest file with name "Manifes.mf".
so now with above components we have to create jar file
command:
jar -cvfm demo.jar manifest.mf JarDemo.class JarDemo$1.class
if we execute the above command jar file will be ready.
once the jar file is ready . we have to run like
Command: java -jar demo.jar
we can execute the same jar file by just double clicking.
Example:
create on java program with main method.
import java.awt.*;
import java.awt.event.*;
public class JarDemo
{
public static void main(String args[]){
Frame f=new Frame();
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){
for(int i=0;i<=10;i++)
System.out.println("I am Closing Window"+i);
System.exit(0);
}
});
f.add(new Label(" i can create Executable jar file");
f.setSize(500,500);
f.setVisible(true);
}
}
javac JarDemo.java
when we run this command we get two .class files JarDemo.class and JarDemo$1.class[Anonymous Innerclass]
so for creating jar file using the above .class fils we need to decide which class would be the main class. for this we need to write one manifest file with name "Manifes.mf".
command:
jar -cvfm demo.jar manifest.mf JarDemo.class JarDemo$1.class
if we execute the above command jar file will be ready.
once the jar file is ready . we have to run like
Command: java -jar demo.jar
we can execute the same jar file by just double clicking.
Comments
Post a Comment