Why does Ant say “NoClassDefFound” when my JAR is on the classpath?

前端 未结 1 1231
不思量自难忘°
不思量自难忘° 2021-01-26 08:33

I am using Java 1.6, Eclipse, and Ant.

The following is my target for creating a jar file and running it:

    
    

        
相关标签:
1条回答
  • 2021-01-26 08:50

    You've set the compile classpath but the App.jar does not include your libs (only the classes you compiled) or a manifest classpath.

    You'll need to do the following:

    <target name="jar">
        <mkdir dir="${jar.dir}" />
        <manifestclasspath property="manifest.classpath"
                           jarfile="${jar.dir}/App.jar">
          <classpath refid="classpath" />
        </manifestclasspath>
        <jar destfile="${jar.dir}/App.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="main.App" />
                <attribute name="Class-Path" value="${manifest.classpath}" />.
            </manifest>
        </jar>
    </target>
    

    See also ant manifestclasspath task

    0 讨论(0)
提交回复
热议问题