Gradle Windows 10 不信任 Launch4J EXE
Gradle Launch4J EXE not trusted by Windows 10
请注意:我已经创建了 this GitHub project right here,可用于完美重现我遇到的问题。
Java 8 在这里 尝试 使用 Launch4J via the gradle-launch4j Gradle 插件构建 Windows 本机 EXE 应用程序。我正在 Mac 上开发 Java Swing 应用程序,但该应用程序必须 运行 作为 Windows 10 上的 Windows EXE。我也在使用ShadowJar 构建我的自包含 "fat jar".
我可以构建我的 (Swing) 应用程序的 fat jar,然后通过 java -jar build/lib/myapp.jar
在我的 Mac 上 运行 它。它启动并且 运行 没有问题。
这是我的 Gradle Launch4J 配置:
launch4j {
mainClassName = 'com.example.windows.hello.HelloWindowsApp'
icon = "${projectDir}/icon.ico"
jdkPreference = 'jdkOnly'
initialHeapSize = 128
jreMinVersion = '1.8.0'
jreMaxVersion = '1.8.9'
maxHeapSize = 512
stayAlive = false
bundledJre64Bit = true
bundledJrePath = '../hello-windows/jre8'
}
当我 运行 ./gradle clean build shadowJar createExe createDistro
它产生:
hello-windows.zip/
hello-windows.exe --> The Windows EXE built by the 'createExe' task
lib/* --> The lib/ dir for the EXE that is also built by the `createExe` task
jre8/ --> OpenJDK JRE8 (copied from the libs/jre8 dir)
所以我复制了那个 ZIP 文件并将其移植到 Windows 10(64 位)机器上。我通过在 Windows Explorer 中双击它来提取 ZIP 和 运行 EXE(我可以确认 确实 将 EXE 视为 Application 类型)。首先我看到这个:
为什么会发生这种情况?是否有任何 Launch4J configurations/settings我可以更改以防止这种情况发生?
提前致谢!
尝试将 build.gradle
中的 bundledJrePath
设置为 jre8
:
launch4j {
...
bundledJrePath = 'jre8'
}
因为在您的情况下,这是解压缩 zip 时 jre 所在的相对路径。
http://launch4j.sourceforge.net/docs.html
<path>
, <minVersion>
, <maxVersion>
The <path>
property is used to specify the absolute or relative path (to the executable) of a bundled JRE, it does not rely on the current directory or <chdir>
. Note that this path is not checked until the actual application execution
注意路径不能包含/bin/javaw.exe
.
当 运行 带有 debug 标志的 exe 像这样
hello-windows.exe --l4j-debug
然后它将在同一目录中创建一个文件launch4j.log
。
在那里您可以检查是否选择了正确的 jre,例如:
...
Bundled JRE: jre8
Check launcher: C:\Users\IEUser\Downloads\hello-windows\jre8\bin\javaw.exe (OK)
...
你的第一个问题更像是一个 Windows 问题。当您从 zip 文件解压缩应用程序时,Windows 自然会将其标记为不安全,事实上,如果您检查应用程序属性选项卡,您将看到一个复选框,您可以在其中删除该不安全属性。对于 Linux.
中的可执行脚本,它与 运行 chmod+x
相同
对于第二部分,我假设您使用的是 Launch4j 的 gradle 插件,有两种主要的配置 Launch4j 的方法,假设您的项目文件夹的结构与包含您的项目的同一文件夹中的 jre 库相同可执行文件夹。
只指定路径就好
../jre
通过指定完整的相对路径
../jre/bin/javaw.exe
你最后生成的 xml 在第一种情况下应该是这样的。
<jre>
<path>../jre</path>
</jre>
要点是 JRE 的路径是相对于可执行文件的位置而不是当前目录。在这种情况下,我们从可执行文件夹后退一个目录到包含jre的文件夹。
您需要按照 here to prevent SmartScreen from blocking it to be run. See also the related discussion in the support forum 所述对 launch4j 创建的可执行文件进行签名。
我对 sschuberth 的上述回答投了赞成票,因为这是对您问题的最佳回答。签署可执行文件将使 SmartScreen 高兴。
此外,我宁愿避免尝试创建可执行文件,甚至对其进行签名,最好创建 MSI。例如,在使用 Nullsoft 之后使用 Javapackager. See also this question. That guy created his own tool。
让全世界每个病毒扫描程序都接受一个可执行文件是非常麻烦的。我有使用 WIX Toolset 创建 MSI 并将其包装到引导程序可执行文件中并使用公司签名证书对其进行签名的经验。但是最后我不得不向 McAfee、Norton、Avast、AVG、KasperSky 和 Trend Micro 发送请求。很高兴随着时间的推移所有人都接受了它,只有趋势科技甚至没有回应。
请注意:我已经创建了 this GitHub project right here,可用于完美重现我遇到的问题。
Java 8 在这里 尝试 使用 Launch4J via the gradle-launch4j Gradle 插件构建 Windows 本机 EXE 应用程序。我正在 Mac 上开发 Java Swing 应用程序,但该应用程序必须 运行 作为 Windows 10 上的 Windows EXE。我也在使用ShadowJar 构建我的自包含 "fat jar".
我可以构建我的 (Swing) 应用程序的 fat jar,然后通过 java -jar build/lib/myapp.jar
在我的 Mac 上 运行 它。它启动并且 运行 没有问题。
这是我的 Gradle Launch4J 配置:
launch4j {
mainClassName = 'com.example.windows.hello.HelloWindowsApp'
icon = "${projectDir}/icon.ico"
jdkPreference = 'jdkOnly'
initialHeapSize = 128
jreMinVersion = '1.8.0'
jreMaxVersion = '1.8.9'
maxHeapSize = 512
stayAlive = false
bundledJre64Bit = true
bundledJrePath = '../hello-windows/jre8'
}
当我 运行 ./gradle clean build shadowJar createExe createDistro
它产生:
hello-windows.zip/
hello-windows.exe --> The Windows EXE built by the 'createExe' task
lib/* --> The lib/ dir for the EXE that is also built by the `createExe` task
jre8/ --> OpenJDK JRE8 (copied from the libs/jre8 dir)
所以我复制了那个 ZIP 文件并将其移植到 Windows 10(64 位)机器上。我通过在 Windows Explorer 中双击它来提取 ZIP 和 运行 EXE(我可以确认 确实 将 EXE 视为 Application 类型)。首先我看到这个:
为什么会发生这种情况?是否有任何 Launch4J configurations/settings我可以更改以防止这种情况发生?
提前致谢!
尝试将 build.gradle
中的 bundledJrePath
设置为 jre8
:
launch4j {
...
bundledJrePath = 'jre8'
}
因为在您的情况下,这是解压缩 zip 时 jre 所在的相对路径。
http://launch4j.sourceforge.net/docs.html
<path>
,<minVersion>
,<maxVersion>
The
<path>
property is used to specify the absolute or relative path (to the executable) of a bundled JRE, it does not rely on the current directory or<chdir>
. Note that this path is not checked until the actual application execution
注意路径不能包含/bin/javaw.exe
.
当 运行 带有 debug 标志的 exe 像这样
hello-windows.exe --l4j-debug
然后它将在同一目录中创建一个文件launch4j.log
。
在那里您可以检查是否选择了正确的 jre,例如:
...
Bundled JRE: jre8
Check launcher: C:\Users\IEUser\Downloads\hello-windows\jre8\bin\javaw.exe (OK)
...
你的第一个问题更像是一个 Windows 问题。当您从 zip 文件解压缩应用程序时,Windows 自然会将其标记为不安全,事实上,如果您检查应用程序属性选项卡,您将看到一个复选框,您可以在其中删除该不安全属性。对于 Linux.
中的可执行脚本,它与 运行chmod+x
相同
对于第二部分,我假设您使用的是 Launch4j 的 gradle 插件,有两种主要的配置 Launch4j 的方法,假设您的项目文件夹的结构与包含您的项目的同一文件夹中的 jre 库相同可执行文件夹。
只指定路径就好
../jre
通过指定完整的相对路径
../jre/bin/javaw.exe
你最后生成的 xml 在第一种情况下应该是这样的。
<jre>
<path>../jre</path>
</jre>
要点是 JRE 的路径是相对于可执行文件的位置而不是当前目录。在这种情况下,我们从可执行文件夹后退一个目录到包含jre的文件夹。
您需要按照 here to prevent SmartScreen from blocking it to be run. See also the related discussion in the support forum 所述对 launch4j 创建的可执行文件进行签名。
我对 sschuberth 的上述回答投了赞成票,因为这是对您问题的最佳回答。签署可执行文件将使 SmartScreen 高兴。
此外,我宁愿避免尝试创建可执行文件,甚至对其进行签名,最好创建 MSI。例如,在使用 Nullsoft 之后使用 Javapackager. See also this question. That guy created his own tool。
让全世界每个病毒扫描程序都接受一个可执行文件是非常麻烦的。我有使用 WIX Toolset 创建 MSI 并将其包装到引导程序可执行文件中并使用公司签名证书对其进行签名的经验。但是最后我不得不向 McAfee、Norton、Avast、AVG、KasperSky 和 Trend Micro 发送请求。很高兴随着时间的推移所有人都接受了它,只有趋势科技甚至没有回应。