我在運行Java程序時遇到了問題(它使用了一些第三方JAR)。我可以編譯它,但是當我在ant中調用我的運行目標時,它說它無法找到我告訴它在類路徑中運行的類。下面是我的build.xml樣子:在ant中設置類路徑的問題
<project basedir="." default="build">
<property name="build" value="build" />
<property name="src" value="." />
<property name="lib" value="lib" />
<path id="classpath">
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${build}">
<include name="*.class" />
</fileset>
</path>
<target name="build">
<javac srcdir="${src}" destdir="${build}">
<classpath refid="classpath" />
</javac>
</target>
<target name="run">
<java classname="FirstClass">
<classpath refid="classpath" />
</java>
</target>
有誰知道我可能是做錯了什麼?
這裏是我的堆棧跟蹤從螞蟻:
ant run Buildfile: build.xml
run:
[java] Could not find GuiStarter. Make sure you have it in your classpath
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:138)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:616)
[java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[java] at org.apache.tools.ant.Task.perform(Task.java:348)
[java] at org.apache.tools.ant.Target.execute(Target.java:357)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:758)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:217)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[java] Java Result: -1
BUILD SUCCESSFUL Total time: 1 second
包含src目錄內的lib目錄?如果你有一個單獨的src目錄作爲basedir,並且lib與src處於同一級別,那麼你必須創建basedir ..並指定屬性src作爲源目錄。或者你可以將你的Ant腳本移動到一個目錄中。 –
你在源代碼中使用默認包嗎?如果不是,你可能需要在類路徑中包含「**/*。class」。 –