我正在尝试向 OS X 用户分发 Java 应用程序。我没有使用 Mac 商店——它将通过我自己的网站进行分发。无论我尝试什么,OS X 的 Gatekeeper 都会拒绝该应用程序。
这是我的方法:
(1) 像往常一样构建应用程序,获取 JAR 文件
(2) 按此处所述使用 appbundler
:https://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html .这会在我的 JAR 周围创建一个运行良好的 .app,并在 MyApp.app/Contents/PlugIns
目录中包含 JVM。
(3) 使用我的开发者证书签署应用程序:
codesign -s 'Developer ID Application: MyCompany Ltd' --deep MyApp.app
...过程成功完成
(4) 验证 .app 将遵守 Gatekeeper 的铁腕法则:
spctl --assess --verbose=4 --type execute MyApp.app
...我得到的结果是:
MyApp.app: a sealed resource is missing or invalid
对我来说似乎不是很冗长!我做错了什么?或者我怎样才能获得更多信息?
SO/Google 围绕“密封资源...”的搜索指的是签名框架(我没有)或建议使用 --force
选项(我试过但没有)进行签名没用)。
最佳答案
你不能使用--deep
。这听起来是个正确的选择,因为您还需要签署嵌入式 JRE,但它不起作用。来自 Apple's docs :
Important: While the --deep option can be applied to a signing operation, this is not recommended. We recommend that you sign code inside out in individual stages (as Xcode does automatically). Signing with --deep is for emergency repairs and temporary adjustments only.
经过大量的努力,我从各种教程中拼凑了这个。 This one是最有帮助的。这是我作为 Ant 脚本的最终解决方案:
<!-- code sign -->
<exec executable="chmod">
<arg line="a+w ${build.dir}/Mac/MyApp.app/Contents/PlugIns/jre"/>
</exec>
<apply executable="codesign"> <!-- note: this loops through the contents of dir -->
<arg line="-f -s 'Developer ID Application: My Organization'"/>
<fileset dir="${build.dir}/Mac/MyApp.app/Contents/PlugIns/jre" />
</apply>
<exec executable="codesign" dir="${build.dir}/Mac">
<arg line="-f -s 'Developer ID Application: My Organization' MyApp.app/Contents/PlugIns/jre"/>
</exec>
<exec executable="codesign" dir="${build.dir}/Mac">
<arg line="-f -s 'Developer ID Application: My Organization' MyApp.app/Contents/PlugIns/jre/Contents/_CodeSignature/CodeResources"/>
</exec>
<!-- also codesign anything else in _CodeSignature (see comments) -->
<exec executable="codesign" dir="${build.dir}/Mac">
<arg line="-f -s 'Developer ID Application: My Organization' MyApp.app"/>
</exec>
<!-- verify codesign -->
<exec executable="codesign" dir="${build.dir}/Mac" failonerror="true">
<arg line="-vv MyApp.app"/>
</exec>
<!-- verify gatekeeper -->
<exec executable="spctl" dir="${build.dir}/Mac" failonerror="true">
<arg line="-vv --assess --type execute MyApp.app"/>
</exec>
另一件需要注意的事情是不要在签名后使用命令行 zip
打包您的应用程序,因为它会破坏应用程序的代码签名。您应该使用 productbuild
、PackageMaker、xip
或 dmg 对其进行打包。
关于java - OS X Gatekeeper 的代码签名 Java 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26938414/