将 Java 项目转换为 .Exe

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11979601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:08:43  来源:igfitidea点击:

Convert Java Project to .Exe

javanetbeansexecutable

提问by Gene

I've created a game project in NetBeans 6.9, and I want to run the project on another computer. The problem is if NetBeans is not installed on the other computer then surely I cannot run the project. Therefore I have to convert my project into a .exe that can be run on other computers without having to install NetBeans.

我在 NetBeans 6.9 中创建了一个游戏项目,我想在另一台计算机上运行该项目。问题是如果 NetBeans 没有安装在另一台计算机上,那么我肯定无法运行该项目。因此,我必须将我的项目转换为可以在其他计算机上运行而无需安装 NetBeans 的 .exe。

Is there a free application that can convert .java to .exe? Please help me to convert my project into a .exe file. Thanks.

是否有可以将 .java 转换为 .exe 的免费应用程序?请帮助我将我的项目转换为 .exe 文件。谢谢。

回答by avirk

Check out these official netbeans article for Packaging and Deploying Desktop Java Applicationsand Developing General Java Applications.

查看这些关于打包和部署桌面 Java 应用程序开发通用 Java 应用程序的官方 netbeans 文章。

From the article

从文章

Running the Application Inside of the IDE

在 IDE 中运行应用程序

When developing applications in the IDE, typically you will need to test and refine them before distributing them. You can easily test an application that you are working on by running the application from the IDE.

在 IDE 中开发应用程序时,通常需要在分发它们之前对其进行测试和优化。您可以通过从 IDE 运行应用程序来轻松测试您正在处理的应用程序。

To run the AnotherGrep project in the IDE, right-clicking the project's node (AnotherGrep) in the Projects window and choose Run Project.

要在 IDE 中运行 AnotherGrep 项目,请在“项目”窗口中右键单击该项目的节点 (AnotherGrep) 并选择“运行项目”。

The xGrep window should open. You can click the Browse button to choose a file in which to search for a text pattern. In the Search Pattern field, type text or a regular expression pattern that you would like to match, and click Search. The results of each match will appear in the xGrep window's Output area.

xGrep 窗口应该打开。您可以单击“浏览”按钮来选择要在其中搜索文本模式的文件。在“搜索模式”字段中,键入要匹配的文本或正则表达式模式,然后单击“搜索”。每个匹配的结果将出现在 xGrep 窗口的输出区域中。

Information on regular expressions that you can use in this application are available here and in many other places on the World Wide Web.

可在此应用程序中使用的有关正则表达式的信息可在此处以及万维网上的许多其他地方获得。

Running the Application Outside of the IDE

在 IDE 之外运行应用程序

Once you have finished developing the application and before you distribute it, you will probably want to make sure that the application also works outside of the IDE.

在完成应用程序的开发和分发之前,您可能希望确保该应用程序也能在 IDE 之外运行。

You can run the application outside of the IDE by following these steps:

您可以按照以下步骤在 IDE 之外运行应用程序:

In your system's file manager (for example, in the My Computer window on Windows XP systems), navigate to PROJECT_HOME/dist and double-click the AnotherGrep.jar file.

在系统的文件管理器中(例如,在 Windows XP 系统上的“我的电脑”窗口中),导航到 PROJECT_HOME/dist 并双击 AnotherGrep.jar 文件。

You will know that the application has started successfully when the xGrep window opens.

当 xGrep 窗口打开时,您就会知道应用程序已成功启动。

If the xGrep window does not open, your system probably does not have a file association between JAR files and the Java Runtime Environment. See Troubleshooting JAR File Associations.

如果 xGrep 窗口未打开,则您的系统可能在 JAR 文件和 Java 运行时环境之间没有文件关联。请参阅JAR 文件关联疑难解答

Distributing the Application to Other Users

将应用程序分发给其他用户

Now that you have verified that the application works outside of the IDE, you are ready to distribute it.
You can distribute the application by following these steps:

既然您已经验证了该应用程序可以在 IDE 之外运行,您就可以分发它了。
您可以按照以下步骤分发应用程序:

1:Create a zip file that contains the application JAR file (AnotherGrep.jar) and the accompanying lib folderthat contains swing-layout-1.0.jar.

1:创建包含应用程序的JAR文件(Zip文件AnotherGrep.jar),并伴随lib folder包含swing-layout-1.0.jar

2:Send the file to the people who will use the application. Instruct them to unpack the zip file, making sure that the AnotherGrep.jarfile and the lib folderare in the same folder.

2:将文件发送给将使用该应用程序的人。指示他们解压缩 zip 文件,确保AnotherGrep.jar文件和lib folder位于同一文件夹中。

The users of your application should be able to run it by double-clicking the JAR file. If this does not work for them, show them the information in the Troubleshooting JAR File Associations section.

应用程序的用户应该能够通过双击 JAR 文件来运行它。如果这对他们不起作用,请向他们显示JAR 文件关联疑难解答部分中的信息

Also some third party tools like Launch4jmay do the trick. For more information see this article on java-to-exe

还有一些像Launch4j这样的第三方工具也可以做到这一点。有关更多信息,请参阅有关java-to-exe 的这篇文章

回答by Gene

See Launch4j. I dislike starting java apps with a batch file. This wraps anything from the root jar all the way up to a complete Java environment in an exe. You get your own icon in the system tray rather than the generic coffee cup. I've used it successfully on a project that has about 300,000 downloads, and it's never been the source of a reported bug. NB It does take some careful reading to pick the right options for your project. But you can set it up with the Ant build script in Netbeans to make the .exe automatically. Very nice and clean. My project includes native libraries. They work fine as well.

请参阅Launch4j。我不喜欢用批处理文件启动 Java 应用程序。这包装了从根 jar 到 exe 中完整 Java 环境的所有内容。您可以在系统托盘中获得自己的图标,而不是通用的咖啡杯。我已经在一个下载量约为 300,000 次的项目中成功使用了它,而且它从未成为报告错误的来源。NB 确实需要仔细阅读才能为您的项目选择正确的选项。但是您可以使用 Netbeans 中的 Ant 构建脚本进行设置,以自动生成 .exe。非常漂亮和干净。我的项目包括本地库。它们也能正常工作。

回答by SANN3

I think the NSISwill help you . Most of the applications using NSIS. Because it is open source.

我认为NSIS会帮助你。大多数应用程序使用 NSIS。因为它是开源的。

Also there is a Eclipse plugin for NSIS to make the process easy.

还有一个 NSIS 的 Eclipse 插件可以简化这个过程。

http://hmne.sourceforge.net/

http://hmne.sourceforge.net/