使用应用程序打包器将Jar转换为Mac OSX应用程序捆绑包

3
我正在尝试使用app bundler将我的.jar打包成MacOSX应用程序包。我正在遵循这篇教程
教程中提到要在高级项目目录下添加一个lib文件夹,但我不知道这是什么意思。我已经到处寻找它,但无法找到。这是我唯一的问题,有人知道吗?
编辑:
这是我的build.xml文件:
<project name="Rage Mage" basedir=".">
<taskdef name="ragemage"
         classname="com.oracle.appbundler.AppBundlerTask"   
         classpath="lib/appbundler-1.0.jar" />

<target name="bundle-RageMage">
    <delete dir="appBundle" failonerror="false"/>
    <mkdir dir="appBundle"/>
    <bundleapp outputdirectory="bundle"
        name="Rage Mage"
        displayname="Rage Mage"
        icon="res/icon.icns"
        identifier="ragemage.src.Window"
        mainclassname="ragemage.src.Window">
        <classpath file="dist/ragemage_1.1.1.jar" />
    </bundleapp>
</target>

Thanks!


我想象中的是,在目录中包含了您所有相关的JAR /库。该教程基于使用NetBeans,它将其主要JAR文件存储在dist目录中,并将所有相关的JAR文件存储在dist / lib目录中。 - MadProgrammer
@MadProgrammer 没看到它是为NetBeans的。你知道Eclipse的替代方案吗? - sparklyllama
基本上是相同的过程,您需要将所有相关的Jars复制到“高级项目”中,无论Eclipse以什么结构进行组织... - MadProgrammer
@MadProgrammer 我已经寻找如何制作MacOSX应用程序包很长一段时间了,而且这个应用程序捆绑工具对我来说仍然无法使用。我尝试了很多方法,也不知道该怎么做。您知道一个简单的方法吗?可能是您之前使用过的。 - sparklyllama
我认为这个教程相当简单明了,虽然我自己还没有真正尝试过,但是你有试着阅读AppBundler任务文档吗? - MadProgrammer
1个回答

4
好的,经过一番尝试,我明白了以下内容:

Ant脚本应该基于如下骨架...

<project name="ButtonDemo" default="bundle-buttonDemo" basedir=".">        
    <taskdef name="bundleapp"
             classname="com.oracle.appbundler.AppBundlerTask"   
             classpath="lib/appbundler-1.0.jar" />
    <!-- See the lib reference here, this is why you need to use the lib directory! -->

    <target name="bundle-buttonDemo">
        <delete dir="appBundle" failonerror="false"/>
        <mkdir dir="appBundle"/>
        <bundleapp outputdirectory="appBundle"
            name="ButtonDemo"
            displayname="Button Demo"
            identifier="components.ButtonDemo"
            mainclassname="components.ButtonDemo">
            <!-- The following is important and should point to your build -->
            <classpath file="dist/ButtonDemo.jar" />
            <!-- You can have multiple instance of classpath if you 3rd party or
                 dependent jars in different locations -->
        </bundleapp>
    </target>
</project>
  • 构建你的项目
  • 运行ant脚本,使用类似 ant -f {你的应用程序打包脚本} 的命令

在这种情况下,应用程序包将被创建在 appBundle 目录中。如果可以的话,请浏览 ButtonDemo.app/Contents/Java 的内容,并确保所有所需的Jar文件都在那里...

愉快的打包吧!

根据更新后的build.xml文件进行更新

1- project 标签未指定 default 目标。可以将其视为你的“主类”或“main”方法,没有这个目标,ant就不知道你想要运行什么...

<project name="Rage Mage" basedir="." default="bundle-RageMage">

2- taskdef 的名称是重要的,您可以在任何脚本中使用它来识别 ant 在命中标记引用时应该执行什么操作...

所以根据你的示例,你需要将 taskdef 的名称从 ragemage 改为 bundleapp 或将 bundleapp 标记更改为 ragemage...

要更改此内容,请进行以下更改...

<taskdef name="bundleapp"
     classname="com.oracle.appbundler.AppBundlerTask"   
     classpath="lib/appbundler-1.0.jar" />

或者这个(在目标bundle-RageMage中)
<ragemage outputdirectory="bundle"
    name="Rage Mage"
    displayname="Rage Mage"
    icon="res/icon.icns"
    identifier="ragemage.src.Window"
    mainclassname="ragemage.src.Window">
    <classpath file="dist/ragemage_1.1.1.jar" />
</ragemage>

就我个人而言,我会将其保留为bundleapp,但这只是我的观点...

3- bundleappdeletemkdiroutputdirectory属性相关联...

<delete dir="appBundle" failonerror="false"/>
<mkdir dir="appBundle"/>
<bundleapp outputdirectory="bundle"...

要么将它们全部设置为appBundle或者bundle,随你喜欢...
4- 你的主类不可能是ragemage.src.Window,而且很可能是Window

评论不适合进行长时间的讨论;此对话已被移至聊天室 - Taryn
1
Java应用程序打包器的下载链接无法使用! - Ayushya
1
@AyushyaChitransh 嗯,有一个替代方案 - MadProgrammer
1
@JAnton 快速搜索一下 - 在 Mac 上打包 Java 应用程序以进行分发,如果您想亲自动手,可以将 Java JRE 打包到您的 macOS 应用程序中。还有自包含应用程序打包,也许可以尝试将 .jar 转换为 Mac OS X 应用程序 - MadProgrammer
1
@JAnton 自从2014年回答这个问题以来,我个人认为它已经过时了。在我快速的谷歌搜索中,我还注意到Jorl17/jar2app,可能值得一看。 - MadProgrammer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接