当前位置: 技术问答>java相关
Java 可以编译成可执行文件吗
来源: 互联网 发布时间:2015-02-06
本文导语: Java只能解释执行吗,如果真是这样,编好的程序怎样发布呢 | 我在此引述一篇文章,希望能有所帮助。 How can I run my Java program as a native executable? - by Borland Developer Support Staff Abstract:A...
Java只能解释执行吗,如果真是这样,编好的程序怎样发布呢
|
我在此引述一篇文章,希望能有所帮助。
How can I run my Java program as a native executable? - by Borland Developer Support Staff
Abstract:A neat trick in JBuilder (3.5 and later) that allows you to run your app as an exe.
Question:
How can I use JBuilder to make my Java program into an native executable?
Answer:
JBuilder does not feature a native compiler but there is a neat feature in JBuilder that will allow you to run you Java programs from an executable, with or without a console. To do this, you will need the following files from your JBuilder "bin" directory (assuming Windows, use comparable files if on Solaris or Linux):
JBuilder.exe
JBuilderW.exe
JBuilder.config
jdk.config
JavaLauncher.dll
"JBuilder.exe" is basically a general purpose executable wrapper for launching Java programs, and "JBuilderW.exe" just wraps "JBuilder.exe". The key to using them is in the file names. "JBuilder.exe" looks for a file called "JBuilder.config" to find the configuration information necessary to launch the Java program. Similarly, "JBuilderW.exe" looks for "JBuilder.exe" and launches it without a console. If you rename the file to "foo.exe" then it will look for "foo.config" for configuration information. The same holds for "JBuilderW.exe". Rename it to "fooW.exe" and you will be able to luanch you java application without a console window, assuming that you have everything setup in "foo.config". For hints on setting on the ".config" file, see the "JBuilder.config" file as well as the "Readme.txt" file in your JBuilder 3.5 "bin" directory.
This little feature is enough to give you a way to launch your Java application from an exe, but now for the fun part. Let's say you have your Java program deployed to "myApp.jar". You've created a "foo.config" that specifies the location of the JDK so that the launcher can launch your program and you've renamed the launcher to "foo.exe". Here's what to do next:
Combine "foo.exe" and "myApp.jar" into one file. To do this in DOS you use a command like:
COPY /B foo.exe+myApp.jar foo.exe
Add "foo.exe" to the classpath in the "foo.config" file with the "addpath" directive:
addpath C:/stuff/foo.exe
To recap, you should now have these files in the same directory: "foo.exe"; "foo.config"; and "JavaLauncher.dll". You should now be able to use "foo.exe" to launch your Java program. Additionally, if you have "fooW.exe" then you will be able to launch your program wihout a console.
Why does it work? Simply put, the structure of executables and jar/zip archives makes this possible. An executable has all of the "important stuff" at the front of the file, so you can attach any amount of junk (or a jar file) onto the end of it. A jar (or zip) file on the other hand, has all of the "important stuff" at the end of the file. So, by combining the two, the executable portion can execute without problems and the executable can also be used as an archive on the class path (assuming that Sun doesn't start checking for "correct" file extensions).
Enjoy!
How can I run my Java program as a native executable? - by Borland Developer Support Staff
Abstract:A neat trick in JBuilder (3.5 and later) that allows you to run your app as an exe.
Question:
How can I use JBuilder to make my Java program into an native executable?
Answer:
JBuilder does not feature a native compiler but there is a neat feature in JBuilder that will allow you to run you Java programs from an executable, with or without a console. To do this, you will need the following files from your JBuilder "bin" directory (assuming Windows, use comparable files if on Solaris or Linux):
JBuilder.exe
JBuilderW.exe
JBuilder.config
jdk.config
JavaLauncher.dll
"JBuilder.exe" is basically a general purpose executable wrapper for launching Java programs, and "JBuilderW.exe" just wraps "JBuilder.exe". The key to using them is in the file names. "JBuilder.exe" looks for a file called "JBuilder.config" to find the configuration information necessary to launch the Java program. Similarly, "JBuilderW.exe" looks for "JBuilder.exe" and launches it without a console. If you rename the file to "foo.exe" then it will look for "foo.config" for configuration information. The same holds for "JBuilderW.exe". Rename it to "fooW.exe" and you will be able to luanch you java application without a console window, assuming that you have everything setup in "foo.config". For hints on setting on the ".config" file, see the "JBuilder.config" file as well as the "Readme.txt" file in your JBuilder 3.5 "bin" directory.
This little feature is enough to give you a way to launch your Java application from an exe, but now for the fun part. Let's say you have your Java program deployed to "myApp.jar". You've created a "foo.config" that specifies the location of the JDK so that the launcher can launch your program and you've renamed the launcher to "foo.exe". Here's what to do next:
Combine "foo.exe" and "myApp.jar" into one file. To do this in DOS you use a command like:
COPY /B foo.exe+myApp.jar foo.exe
Add "foo.exe" to the classpath in the "foo.config" file with the "addpath" directive:
addpath C:/stuff/foo.exe
To recap, you should now have these files in the same directory: "foo.exe"; "foo.config"; and "JavaLauncher.dll". You should now be able to use "foo.exe" to launch your Java program. Additionally, if you have "fooW.exe" then you will be able to launch your program wihout a console.
Why does it work? Simply put, the structure of executables and jar/zip archives makes this possible. An executable has all of the "important stuff" at the front of the file, so you can attach any amount of junk (or a jar file) onto the end of it. A jar (or zip) file on the other hand, has all of the "important stuff" at the end of the file. So, by combining the two, the executable portion can execute without problems and the executable can also be used as an archive on the class path (assuming that Sun doesn't start checking for "correct" file extensions).
Enjoy!
|
用installanywhere做成安装包。安装会自动产生exe文件。
或用jet把class文件做成exe文件。
或用jet把class文件做成exe文件。
|
download : http://www.sun.com/solaris/jit/
jit can compile to exe file
jit can compile to exe file
|
可以用一些软件打包成exe文件。如果想跨平台应用,还是用jar发布比较好。
|
用 Visual J++ 吧,虽说不是pure java,可是能很容易的达到你的要求。