我正在尝试使用jarbundler创建带有ant的.app文件。但是我收到以下错误:

找不到taskdef类net.sourceforge.jarbundler.JarBundler
使用类加载器
AntClassLoader [/Users/Ida/NetBeansProjects/supernova/build/classes/lib/jarbundler-core-3.3.0.jar]

我的build.xml看起来像这样:

 <path id="classpath">
        <fileset dir="dist/lib">
            <include name="*.jar"/>
        </fileset>
    </path>

    <target name="clean">
        <delete dir="build"/>
    </target>

    <target name="compile">
        <mkdir dir="build/classes"/>
        <javac srcdir="src" destdir="build/classes">
            <classpath>
                <path refid="classpath"/>
                <path location="${jar.dir}/${ant.project.name}.jar"/>
            </classpath>
        </javac>
        <copy todir="build/classes">
            <fileset dir="src" excludes="**/*.java"/>
        </copy>
    </target>

    <target name="dist">
        <mkdir dir="build/classes/lib"/>
        <copy flatten="true" todir="build/classes/lib" includeemptydirs="false">
            <fileset dir="dist/lib">
                <include name="*.jar"/>
            </fileset>
        </copy>
        <mkdir dir="build/jar"/>
        <jar destfile="build/jar/SuperNova.jar" basedir="build/classes">
            <fileset dir="dist/lib">
                <include name="*.jar"/>
            </fileset>
            <manifest>
                <attribute name="Main-Class" value="com.lumenradio.supernova.SuperNovaApp"/>
            </manifest>
        </jar>
    </target>

    <target name="jar">
        <mkdir dir="build/jar"/>
        <jar destfile="build/jar/SuperNova.jar" basedir="build/classes">
            <fileset dir="dist/lib">
                <include name="*.jar"/>
            </fileset>
            <manifest>
                <attribute name="Main-Class" value="com.lumenradio.supernova.SuperNovaApp"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="jar">
        <java fork="true" classname="com.lumenradio.supernova.SuperNovaApp">
            <classpath>
                <path refid="classpath"/>
                <path location="build/jar/SuperNova.jar"/>
            </classpath>
        </java>
    </target>



    <target name='package-app'>
        <taskdef name="jarbundler" classname="net.sourceforge.jarbundler.JarBundler">
            <classpath>
                <pathelement location="build/classes/lib/jarbundler-core-3.3.0.jar"/>
            </classpath>
        </taskdef>
        <jarbundler dir="dist" name="SuperNova"
            mainclass="com.lumenradio.supernova.SuperNovaApp"
            jar="build/jar/SuperNova.jar"/>
    </target>

是否有人现在为什么会出现此错误以及如何解决?

编辑

谢谢你的帮助。我现在可以构建.app文件,但是当我尝试运行它时,出现以下错误:

错误:找不到或加载主类
com.lumenradio.supernova.SuperNovaApp

我的目标现在看起来像这样:
<target name='package-app'>
        <taskdef name="jarbundler" classpath="build/classes/lib/jarbundler-core-3.3.0.jar"
        classname="com.ultramixer.jarbundler.JarBundler"/>

        <jarbundler dir="dist" name="SuperNova"
            jar="build/jar/SuperNova.jar"
            mainclass="com.lumenradio.supernova.SuperNovaApp"
            icon="SuperNova copy.icns"
            stubfile="universalJavaApplicationStub"
            useJavaXKey="true"
            jvmversion="1.7+"/>
    </target>

最佳答案

我下载了jar进行查看,我认为问题是您的classname错误。 JarBundler类位于com.ultramixer.jarbundler.JarBundler中,因此请尝试以下操作:

    <taskdef name="jarbundler" classname="com.ultramixer.jarbundler.JarBundler">
        <classpath>
            <pathelement location="build/classes/lib/jarbundler-core-3.3.0.jar"/>
        </classpath>
    </taskdef>

另外,由于仅加载单个库,因此不需要使用嵌套的类路径来代替taskdefclasspath属性,因此可以对其进行一些简化:
    <taskdef
        name="jarbundler"
        classname="com.ultramixer.jarbundler.JarBundler"
        classpath="build/classes/lib/jarbundler-core-3.3.0.jar"
    />

关于java - 将Jarbundler与 Ant 配合使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45081471/

10-08 22:16