簡體   English   中英

從Mac OS X的.app文件夾運行諸如hdiutil之類的外部程序

[英]Running an external program like hdiutil from an .app folder on Mac OS X

我制作了一個.app文件夾,其中包含一個Java應用程序和一個JRE。 我使用app-bundle-maven插件創建.app文件夾。

我的Java應用程序從ISO映像創建一個.dmg文件,並通過將hdiutil作為子進程啟動來執行此操作。

從命令行或IDE運行時,此方法可以正常工作,但從.app文件夾啟動時,此方法將失敗。

ProcessBuilder拋出一個IOException,未找到/ usr / bin / hdiutil。

我的問題是:.app文件夾是否像沙箱? Info.plist文件中是否存在可以覆蓋沙箱行為的設置?

Info.plist的:

<?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>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleExecutable</key>
    <string>JavaAppLauncher</string>
    <key>CFBundleIconFile</key>
    <string>usbboot.icns</string>
    <key>CFBundleIdentifier</key>
    <string>de.bamamoto.mactools.usbboot.USBBoot</string>
    <key>CFBundleDisplayName</key>
    <string>USBBoot</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>USBBoot</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0-SNAPSHOT</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>NSHumanReadableCopyright</key>
    <string></string>
    <key>NSHighResolutionCapable</key>
    <true/>
    <key>JVMRuntime</key>
    <string>JRE</string>
    <key>JVMMainClassName</key>
    <string>de.bamamoto.mactools.usbboot.USBBoot</string>
    <key>JVMClassPaths</key>
    <array>
      <string>de/bamamoto/webmusic/USBBoot/1.0-SNAPSHOT/USBBoot-1.0-SNAPSHOT.jar</string>
    </array>
    <key>JVMVersion</key>
    <string>1.6+</string>
    <key>JVMOptions</key>
    <array>
       <string>-Dapple.laf.useScreenMenuBar=true</string>
      <string>-Xdock:name=USBBoot</string>
      <string>-Djava.util.Arrays.useLegacyMergeSort=true</string>
    </array>
    <key>JVMArguments</key>
    <array/>
    <key>LauncherWorkingDirectory</key>
    <string>$APP_ROOT</string>
  </dict>
</plist>

我找到了解決此問題的方法。 位於JREs lib文件夾中的名為jspawnhelper的文件在復制操作期間丟失了執行標志。 使用ProcessBuilder.start()或Runtime.exec()方法調用時需要此文件。

引發的未找到可執行文件的IOException具有誤導性。 在該文件上設置了執行標志后,一切都會按預期進行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM