可能重复:
Why does Ant say “NoClassDefFound” when my JAR is on the classpath?
我目前有3个我在Ant中编译的java文件。它使用的是Java GUI,因此它依赖于2个.jar文件。使用javac和jar进行编译在Ant中运行良好。但是,一旦我双击jar文件来运行它,它就不会运行。当我尝试在Ant中使用Java运行它时会发生以下错误。
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
[java] at tictactoe.General.main(Unknown Source)
[java] Caused by: java.lang.ClassNotFoundException: org.jdesktop.layout.GroupLayout$Group
等等...
这是我的Ant文件` Tic Tac Toe - CIS3760A1
<path id="classpath">
<fileset dir="lib" includes="*.jar" />
</path>
<target name="init">
<mkdir dir="build" />
<mkdir dir="dist" />
</target>
<target name="compile" depends="init">
<javac srcdir="src" destdir="build" classpathref="classpath" includeantruntime="false" />
</target>
<target name="jar" depends="compile">
<jar destfile="dist/CIS3760A1.jar" basedir="build">
<manifest>
<attribute name="Main-Class" value="tictactoe.General"/>
<attribute name="Class-Path" value="lib/org-jdesktop-layout.jar lib/swing-layout-1.0.4.jar"/>
</manifest>
</jar>
</target>
<target name="clean">
<delete dir="build" />
<delete dir="dist" />
</target>
<target name="run" depends="jar">
<java jar="dist/CIS3760A1.jar" fork="true" classpathref="classpath" />
</target>
`
答案 0 :(得分:2)
JAR文件是否包含带有2个必需jar的lib子目录的目录?从脚本的外观来看,它构建成一个dist目录,看起来它没有相对于主jar所需的lib目录。