当前位置: 技术问答>java相关
在java中如何生成可单独安装运行的应用程序呀?就像.exe一样!
来源: 互联网 发布时间:2015-02-27
本文导语: | Make a JAR executable In the manifest file of a JAR, it is possible to specify the class to be used when the JVM is lauched with the JAR as parameter. The class must have a main(). Try with this simple class import java.awt.*; import ...
|
Make a JAR executable
In the manifest file of a JAR, it is possible to specify the class to be used when the JVM is lauched with the JAR as parameter. The class must have a main().
Try with this simple class import java.awt.*;
import java.awt.event.*;
public class MyClass {
public static void main(String[] args) {
Frame f = new Frame();
f.addWindowListener
(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
f.add(new Label("Hello world"));
f.setSize(200,200);
f.setVisible(true);
}
}
Then create this manifest file (manifest.mft) with any text editor. Manifest-Version: 1.0
Main-Class: MyClass
Classpath: .MyJar.jar
Next, you include the manifest file in the JAR (MyJar.jar) with the MyClass class. jar cvfm MyJar.jar manifest.mft MyClass.class
Then you are able to start the MyClass.class by double-clicking on the MyJar.jar file (if the JRE is correctly installed) or by typing java -jar MyJar.jar
On NT, you can also make JARs run from the command-line by setting the PATHEXT environment variable, for example set PATHEXT=.EXE;.BAT;.CMD;.JAR
Then if you have the jar file MyJar.jar accessible via the PATH environment variable, typing "MyJar" on the DOS command line will invoke "java -jar MyJar.jar" .
In the manifest file of a JAR, it is possible to specify the class to be used when the JVM is lauched with the JAR as parameter. The class must have a main().
Try with this simple class import java.awt.*;
import java.awt.event.*;
public class MyClass {
public static void main(String[] args) {
Frame f = new Frame();
f.addWindowListener
(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
f.add(new Label("Hello world"));
f.setSize(200,200);
f.setVisible(true);
}
}
Then create this manifest file (manifest.mft) with any text editor. Manifest-Version: 1.0
Main-Class: MyClass
Classpath: .MyJar.jar
Next, you include the manifest file in the JAR (MyJar.jar) with the MyClass class. jar cvfm MyJar.jar manifest.mft MyClass.class
Then you are able to start the MyClass.class by double-clicking on the MyJar.jar file (if the JRE is correctly installed) or by typing java -jar MyJar.jar
On NT, you can also make JARs run from the command-line by setting the PATHEXT environment variable, for example set PATHEXT=.EXE;.BAT;.CMD;.JAR
Then if you have the jar file MyJar.jar accessible via the PATH environment variable, typing "MyJar" on the DOS command line will invoke "java -jar MyJar.jar" .
|
使用jet生成,
到
http://www.softhouse.com.cn/cgi-bin/biank/search?libname=freenew&page_no=3&word=jet&dispnum=10
到
http://www.softhouse.com.cn/cgi-bin/biank/search?libname=freenew&page_no=3&word=jet&dispnum=10
|
好像不能用哎
|
简单的可以用如hello world 我实验过,可以我在将JMFStudio生成.exe时却没有成功,让我report bug
|
用JET时你的JDK必须是1.3.0 OR 1.3.02我不知道在那里下载!我用的是JDK1.3,但JBUILDER5中的JDK是1.3.02
|
做成jar的,需要jre。