如何使用 Eclipse 在 JAVA 中创建可执行文件(像 .exe 一样双击启动程序的文件)?
我已经用 java 创建了一个程序,现在我想从中创建一个可执行文件。 我是java新手,我不知道它是否应该是.exe
。 我将项目导出到 .jar
文件,但是当我双击它时,它会打开“打开方式”窗口。
我想将我的项目导出到双击运行我的程序的文件。
有什么解决办法吗?
I've created a program in java and now I want to create an executable from it.
I'm new to java, I don't know if it should be a .exe
.
I'we exported my project to a .jar
file, but when I double-click it it opens "open with" window.
I want to export my project to a file that runs my program on double-click.
Is there any solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
导出--> Java -->可运行的 Jar 文件 -->指定要运行的具有静态 main 方法的类。
双击Jar文件运行..
谢谢...
Export --> Java --> Runnable Jar file --> Specify the class with static main method to run.
Double click on the Jar file to run..
Thanks...
Java 编译为 JVM 创建字节代码,因此在编译期间不会创建本机二进制可执行文件(如 C 或 C++ 程序)。这是Java的一个特性。
要将应用程序部署到多个系统,它们必须具有 JRE。这些 .jar 文件可以从命令行启动(请参阅:http: //download.oracle.com/javase/tutorial/deployment/jar/run.html)
一些供应商通过启动 JRE 来运行其应用程序的 JAR 的批处理文件来解决这个问题(然后将它们放在开始菜单中) 、桌面等带有精美的图标)。
如果您希望人们安装您的应用程序(尤其是从网页或通过网络),您可能需要一个 Java Web Start 包(有关在 Eclipse 中打包一个包的信息,请参阅:http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fjava_web_start.htm)
Java compiliation creates byte code for the JVM, so a native, binary executable is not created during compiliation (like C or C++ programs). This is a feature of Java.
To deploy an application to multiple systems they must have the JRE. These .jar files can be launched from the command line (see this: http://download.oracle.com/javase/tutorial/deployment/jar/run.html)
Some vendors get around this with batch files that launch the JRE to run their application's JAR (and then put these in the start menu, desktop, etc with a fancy icon).
If you want people to install your app (especially from a web page or over a network) you probably want a Java Web Start package (see this for crating one in Eclipse: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fjava_web_start.htm)
如果您只想让它在您的计算机上运行,您可以使用“打开方式”对话框,使用 JDK_DIRECTORY\bin 中的 javaw.exe 打开它。或者,如果您确实想将其设为 EXE,您可以查看一些答案 此处。
If you just want it to be runnable on your computer, you can use the open with dialog to open it with javaw.exe in JDK_DIRECTORY\bin. Alternatively, if you really wanted to make it an EXE, you could look at some of the answers here.
要么按照 @dacwe 提到的链接进行操作,要么我建议根据操作系统在 java 和 jar 之间设置永久连接,那么它总会发生。
在 Windows 上,您可以通过右键单击任何 jar 然后打开并在 jre 安装的 bin 文件夹中找到 javaw.exe 来完成此操作。
Either do as in the link mentioned by @dacwe or I would suggest to depending on operating system set a permanent connection between java and jars, then it will always happen.
On Windows you do it by right clicking on any jar then open with and find your javaw.exe in bin folder of your jre installation.
我认为您正在寻找一种比 Java Web Start 更简单的方法。
我假设您是 Windows 用户,因为您需要 .exe 文件。
因此,一旦导出了 MyProgram.jar 文件,您只需创建一个 .bat 文件
其中包含唯一一行:
并将此
execute.bat
文件放在与 MyProgram.jar 相同的文件夹中这种方法也适用于 Linux,只需将它放在类似的文件中并执行相同的操作命令。
请阅读此处 http://javabeanz。 wordpress.com/2009/01/29/running-an-executable-jar-from-command-line/ 了解更多说明。
I think you are looking for a simpler approach than Java Web Start.
I assume that you are a Windows User, since you want a .exe file.
So once you have the exported MyProgram.jar file, you only need to create a .bat file
that contains a sole line:
and place this
execute.bat
file in the same folder as your MyProgram.jarThis approach works for Linux too, only you need to place it inside a similar file and execute the same command.
Read here http://javabeanz.wordpress.com/2009/01/29/running-an-executable-jar-from-command-line/ for more explanations.