我正在使用 maven os x 应用程序包插件,这样我就可以创建一个 java 启动器的 mac 可执行版本。我必须这样做作为两个步骤的一部分,以免给我的用户 Gatekeeper 带来麻烦......
我必须配置一个自定义 plist 以正确设置 java 工作目录(单击 jar 时代码运行良好,单击 .app 时崩溃并退出代码 1)
该插件允许您制作自己的 plist 并指示它在 pom 中的位置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>osxappbundle-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<configuration>
<mainClass>com.helion3.Launcher</mainClass>
<dictionaryFile>${basedir}/src/main/resources/Info.plist</dictionaryFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
</plugin>
该文件存在于该位置。当我运行时mvn package
,它现在失败了:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:osxappbundle-maven-plugin:1.0-alpha-1:bundle (default) on project liftoff: Could not find resource for template /Users/myacct/Documents/workspace/MyProgram/src/main/resources/Info.plist
当我运行vi /Users/myacct/Documents/workspace/MyProgram/src/main/resources/Info.plist
时,文件正确打开。
我的 plist 本身应该是有效的,因为我复制了最初生成的那个,添加了一个 workingDirectory 键,并用插件的占位符替换了一些值。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>CFBundleName</key>
<string>${bundleName}</string>
<key>CFBundleVersion</key>
<string>${describe}</string>
<key>CFBundleAllowMixedLocalizations</key>
<string>true</string>
<key>CFBundleExecutable</key>
<string>JavaApplicationStub</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleIconFile</key>
<string>GenericJavaApp.icns</string>
<key>Java</key>
<dict>
<key>WorkingDirectory</key>
<string>$APP_PACKAGE/Contents/Resources</string>
<key>MainClass</key>
<string>${mainClass}</string>
<key>JVMVersion</key>
<string>1.4+</string>
<key>ClassPath</key>
${classpath}
</dict>
</dict>
</plist>