Java 在 IntelliJ for Windows 中生成可执行文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53854635/
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-08-11 00:55:30  来源:igfitidea点击:

Generating executable file in IntelliJ for Windows

javaintellij-ideajavafxexecutable

提问by Miguel Mesquita Alfaiate

I used to work on an IntelliJ project that was started before I started working on it. This project had a configuration that allowed me to generate an EXE file that could easily be sent to windows users.

我曾经在一个 IntelliJ 项目上工作,这个项目在我开始工作之前就已经开始了。这个项目有一个配置,允许我生成一个可以轻松发送给 Windows 用户的 EXE 文件。

It would generate a massive EXE file bundled with all the needed JARs of the application, and upon running it the first time, it would silently "install" itself into the AppData folder, as if it were a regular windows setup file, even though the user would not even notice it doing that installation.

它会生成一个与应用程序所有需要的 JAR 捆绑在一起的大量 EXE 文件,并且在第一次运行它时,它会默默地将自己“安装”到 AppData 文件夹中,就好像它是一个常规的 Windows 安装文件,即使用户甚至不会注意到它在安装。

I am trying to configure a project in IntelliJ to do the exact same thing, but first I have not been able to output the exe file by selecting "exe" as the Java FX native bundle type. It just generates a .jnlp and .jar file. When I select "all", as per some other post here in stackoverflow, it generates an exe file, but only with a few kb in size, which does not contain any of the .jar files that should be part of it. Moreover, when I try to open it, it just crashes saying the main class was not found.

我正在尝试在 IntelliJ 中配置一个项目以执行完全相同的操作,但首先我无法通过选择“exe”作为 Java FX 本机包类型来输出 exe 文件。它只生成一个 .jnlp 和 .jar 文件。当我选择“全部”时,根据 stackoverflow 中的其他一些帖子,它会生成一个 exe 文件,但只有几 kb 的大小,其中不包含任何应该成为其中一部分的 .jar 文件。此外,当我尝试打开它时,它只是崩溃,说找不到主类。

Am I missing some setting for building the project? I am using IntelliJ 2018.3.2

我是否缺少构建项目的一些设置?我正在使用 IntelliJ 2018.3.2

Here are some screenshots:

以下是一些截图:

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

采纳答案by Miguel Mesquita Alfaiate

I have been able to get past this error, after changing the verbosity of the compilation and going through the logs.

在更改编译的详细程度并查看日志后,我已经能够克服这个错误。

There was a log message which helped fixing this:

有一条日志消息有助于解决这个问题:

The process complained about the Inno Setup Compilermissing, which was right. Makes me wonder why IntelliJ would have that feature built in if it depends on external tools but does not notify the user clearly of this.

过程抱怨Inno Setup Compiler失踪,这是正确的。让我想知道为什么 IntelliJ 会内置该功能,如果它依赖于外部工具但没有明确通知用户这一点。

Detected [iscc.exe] version 0.0 but version 5.0 is required.

After going to the Inno Setup site, downloading and installing the tool, I was able to get the executable to be generated.

转到 Inno Setup 站点,下载并安装该工具后,我能够生成要生成的可执行文件。

Now I am struggling with another error, which is the executable complaining about the main class referenced in the Artifact not being found, but at least I have moved past the first problem! Going to tackle this one now...

现在我正在为另一个错误而苦苦挣扎,这是可执行文件抱怨没有找到 Artifact 中引用的主类,但至少我已经解决了第一个问题!现在要解决这个问题...

回答by Naween Banuka

The best solution for this is using exe generator software. There is plenty of exe generators out there.

最好的解决方案是使用 exe 生成器软件。那里有很多 exe 生成器。

EXE4Jis the most simple & easy tool to use.

EXE4J是最简单易用的工具。

In EXE4J,
You can upload your main jar file and select the main class.

在 EXE4J 中,
您可以上传主 jar 文件并选择主类。

I think this will be solved your problem.

我认为这将解决您的问题。

回答by Alex G.

This may be due to you`ve extracted Jars to your output root, while you neet to Put it(you can check difference by deleting everything from your output root in Output Layout screen and then just right click on jar on the right side, you will see two options here, try another one

这可能是因为您已经将 Jars 提取到您的输出根目录,而您需要放置它(您可以通过在输出布局屏幕中删除输出根目录中的所有内容来检查差异,然后右键单击右侧的 jar,您可以将在这里看到两个选项,请尝试另一个