Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Ant apache NoClassDefFoundError_Java_Xml_Ant_Javac - Fatal编程技术网

Java Ant apache NoClassDefFoundError

Java Ant apache NoClassDefFoundError,java,xml,ant,javac,Java,Xml,Ant,Javac,我在构建build.xml文件时遇到了一些问题。我知道标签javac的类路径有一些问题,但我不知道如何解决它 [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.privat

我在构建build.xml文件时遇到了一些问题。我知道标签javac的类路径有一些问题,但我不知道如何解决它

[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”:


Criando os diretorio类,文件e区。
编译项目。
杰兰多·奥加多·普罗杰托。
执行项目。


如果有人能帮助我,我将不胜感激。

看起来您正在尝试从JavaSE运行JavaEE应用程序。 javax/ws/rs/core/Response类仅在JavaEE下可用(在您的web服务器上)。
您的build.xml target=“all”尝试在JavaSE下执行您的webapp。摆脱它。将target=“dist”设为默认目标,然后将您的jar上载到Web服务器(Tomat等)。

Hi,tks获取答案。您知道如何构造目标“compile”来导入库吗?您不需要导入库。类路径将允许编译java文件。然后dist生成您的jar,它应该是一个WAR文件。我认为您需要研究如何创建JavaEE包,而不是标准JAR文件。WAR文件上载到Web服务器并运行它。您不能从java命令行运行它。
<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>