0
我在構建文件build.xml時遇到了一些問題。我知道標記javac的類路徑存在一些問題,但我不知道如何解決它。Ant apache NoClassDefFoundError
[java] Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/core/Response
[java] at java.lang.Class.getDeclaredMethods0(Native Method)
[java] at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
[java] at java.lang.Class.getMethod0(Class.java:2764)
[java] at java.lang.Class.getMethod(Class.java:1653)
[java] at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
[java] at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
[java] Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.Response
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
我的項目庫中的 「/的WebContent/WEB-INF/lib中/」,這是我的文件 「的build.xml」:
<property name="src" value="\${basedir}/src" />
<property name="build" value="classes" />
<property name="dist" value="dist" />
<property name="package" value="*" />
<target name="init">
<echo> Criando os diretorio classes, doc e dist.</echo>
<mkdir dir="..\${build}" />
<mkdir dir="..\${dist}" />
</target>
<target name="compile" depends="init" >
<echo> Compilando o projeto.</echo>
<javac srcdir="\${src}" destdir="..\${build}" includeantruntime="false">
<classpath>
<fileset dir="\${basedir}/WebContent/WEB-INF/lib/">
<include name="jersey-server-1.4.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="dist" depends="compile">
<echo> Gerando o .jar do projeto.</echo>
<jar jarfile="..\${dist}/InfosoundWebApp.jar" basedir="..\${build}">
<!-- Tornando o jar executável-->
<manifest>
<attribute name="Main-Class" value="com.informatec.restfull.ServerRestfull"/>
</manifest>
</jar>
</target>
<target name="all" depends="dist">
<echo> Executa o projeto.</echo>
<java jar="..\${dist}/InfosoundWebApp.jar" fork="true" />
</target>
<target name="clear">
<delete dir="..\${build}" />
<delete dir="..\${dist}" />
</target>
如果有人能幫助我,我將不勝感激。
嗨,tks爲答案。你知道我如何構建目標「編譯」來導入庫? – pedrodurek 2015-01-27 11:12:00
您不應該需要導入庫。類路徑將允許你的java文件進行編譯。然後dist使你的jar,這應該是一個WAR文件。我認爲你需要研究如何創建JavaEE包,而不是標準的JAR文件。 WAR文件上傳到網絡服務器並運行它。你不要從java命令行運行它。 – 2015-01-28 03:28:32