java - 为什么在使用 --option 运行时进行代码设计后无法启动 Java 应用程序
问题描述
我正在为 Mac OS 分发 Java 应用程序,并使用 appbundler 来构建应用程序。现在有必要对应用程序进行公证,还需要启用 Hardened Runtime 通过公证。对此存在一些问题:
- 如果我在没有
--option runtime
它的情况下对应用程序进行代码签名,但无法通过公证 - 如果我用
--option runtime
它对应用程序进行代码设计,则可以通过公证,但无法启动。
使用 Maven 构建应用程序:
<build>
<finalName>${organization.name}-${version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.panayotis</groupId>
<artifactId>appbundler</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${build.directory}/${build.finalName}"/>
<taskdef name="bundleapp" classname="com.oracle.appbundler.AppBundlerTask"/>
<bundleapp outputdirectory="${build.directory}/${build.finalName}"
name="${organization.name}"
displayname="${organization.name}"
identifier="com.company.product"
shortversion="${revision}"
icon="src/main/resources/icons/Icon.icns"
mainclassname="org.springframework.boot.loader.JarLauncher"
copyright="2019 Company">
<runtime dir="${project.basedir}/../misc/jdk-11.0.4+11/Contents/Home"/>
<classpath file="${build.directory}/${organization.name}-${revision}.jar"/>
<option value="-Dspring.config.location=classpath:/application.yml,file:./application.yml"/>
<option value="-Djava.awt.headless=false"/>
<option value="-Xmx512m"/>
</bundleapp>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
代码设计流程:
codesign --options runtime --entitlements entitlements.plist --sign "Dev. ID" App.app/Contents/PlugIns/jdk-11.0.4+11
find "App.app/Contents/Resources/additional executables" -type -f -exec "codesign --options runtime --entitlements entitlements.plist --sign "Dev. ID" {}"
codesign --options runtime --entitlements entitlements.plist --sign "Dev. ID" App.app/Contents/Java/App.jar
codesign --options runtime --entitlements entitlements.plist --sign "Dev. ID" App.app/Contents/MacOS/JavaAppLauncher
权利:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-executable-page-protection</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
</dict>
</plist>
从终端启动应用程序时出错:
2019-08-08 10:28:51.443 JavaAppLauncher[4526:559342] int launch(char *, int, char **) Launchpath: /Applications/App.app/Contents/PlugIns/jdk-11.0.4+11/Contents/Home/lib/jli/libjli.dylib
2019-08-08 10:28:51.449 JavaAppLauncher[4526:559342] int launch(char *, int, char **) Error launching JVM Runtime (jdk-11.0.4+11) Relative Path: '/Applications/App.app/Contents/PlugIns/jdk-11.0.4+11' (dylib: /Applications/App.app/Contents/PlugIns/jdk-11.0.4+11/Contents/Home/lib/jli/libjli.dylib)
error: JRELoadError
解决方案
正确的决定是摆脱 appbundle 插件。我编写了自己的启动器,使用启用了强化运行时的 X-Code 构建它,并且运行良好。
推荐阅读
- python - Django:将带有外键的表单cleaned_data保存为会话项
- azure - 通过 CI/CD 中的 ARM 模板删除 ADF 中的资源不起作用
- unity3d - 如何在没有 SphereCollider.Create() 工厂方法调用的情况下对 Unity.Physics.SphereCollider 结构进行 CastRay()
- azure - dir:无法在 azure devops 管道中访问
- python - 有没有更好的方法来对 2d numpy 数组中的连续列向量执行计算?
- iis - 无法从 IIS FTP 访问符号链接
- reactjs - 在反应中过滤的图像的不同 alt 属性
- sql - ORACLE DB 查询 - 教职员工的最高津贴
- r - 随机数据矩阵
- javascript - 回到上一步为什么不显示v-show?