我在Ant中遇到了一個問題,它會一直困擾着我,而我似乎沒有找到解決方案。我在Java中的RMI項目,該項目完成後,將以下文件:當我嘗試運行我的程序時出現螞蟻錯誤
<project name="StockageRMI" default="compile">
<target name="compile">
<javac destdir="classes">
<src path="src/db/"/>
<classpath>
<fileset dir="lib/">
<include name="**/*.jar" />
</fileset>
<fileset dir="classes/">
<include name="**/*.class" />
</fileset>
</classpath>
</javac>
<javac destdir="classes">
<src path="src/stockage"/>
<classpath>
<fileset dir="lib/">
<include name="**/*.jar" />
</fileset>
<fileset dir="classes/">
<include name="**/*.class" />
</fileset>
</classpath>
</javac>
<javac destdir="classes">
<src path="src/server"/>
<classpath>
<fileset dir="lib/">
<include name="**/*.jar" />
</fileset>
<fileset dir="classes/">
<include name="**/*.class" />
</fileset>
</classpath>
</javac>
<javac destdir="classes">
<src path="src/client"/>
<classpath>
<fileset dir="lib/">
<include name="**/*.jar" />
</fileset>
<fileset dir="classes/">
<include name="**/*.class" />
</fileset>
</classpath>
</javac>
</target>
<target name="rmic" depends="compile">
<rmic classname="stockage.StockageImpl" base="classes/">
<classpath>
<fileset dir="lib/">
<include name="**/*.jar" />
</fileset>
<fileset dir="classes/">
<include name="**/*.class" />
</fileset>
</classpath>
</rmic>
</target>
<target name="runServer" depends="rmic,runStockage">
<java classname="server.ServerImpl" fork="true" failonerror="true" >
<classpath>
<fileset dir="lib/">
<include name="**/*.jar" />
</fileset>
<fileset dir="classes/">
<include name="**/*.class" />
</fileset>
</classpath>
</java>
</target>
<target name="runStockage">
<java classname="stockage.StockageImpl" fork="true" failonerror="true" >
<classpath>
<fileset dir="lib/">
<include name="**/*.jar" />
</fileset>
<fileset dir="classes/">
<include name="**/*.class" />
</fileset>
</classpath>
</java>
</target>
</project>
目標「編譯」和「RMIC」的工作就好了,問題是,當我嘗試運行「runStockage」。我得到的錯誤:
Exception in thread "main" java.lang.NoClassDefFoundError: stockage/StockageImpl
[java] Caused by: java.lang.ClassNotFoundException: stockage.StockageImpl
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[java] Java Result: 1
這是很奇怪的,因爲如果我嘗試這樣做在終端,java命令工作正常,並且它具有相同的類路徑中的javac,因爲它具有相同的依賴關係:
javac -cp lib/mongo-java-driver-2.11.1.jar:lib/rmiio-2-1.0.0.jar:lib/commons-logging-1.1.3.jar:classes -d classes src/stockage/StockageImpl.java
rmic -classpath lib/mongo-java-driver-2.11.1.jar:lib/rmiio-2-1.0.0.jar:lib/commons-logging-1.1.3.jar:classes -d classes stockage.StockageImpl
java -classpath lib/mongo-java-driver-2.11.1.jar:lib/rmiio-2-1.0.0.jar:lib/commons-logging-1.1.3.jar:classes server.ServerImpl
以上所有三個命令都可以正常工作,問題在於ant。正如你所看到的,javac,java和rmic使用相同的依賴和jar文件,所以我在Ant中做了同樣的事情,但它不起作用。我相信在這個過程中這是愚蠢的,但我似乎無法在過去6個小時內弄清楚。任何人都有線索?