2011-09-17 6 views
1

안녕하세요 세계 앱의 JAR 파일을 생성하기 위해 Spring과 ANT 스크립트를 사용하여 간단한 hello world 앱을 작성했습니다. JAR이 생성되고 클래스가 올바르게 컴파일됩니다. 그런 다음 JAR을 내 tomcat webapps 폴더에 복사하고 tomcat을 시작한 다음 index.jsp 페이지를로드했습니다. index.jsp 페이지에서 탐색하려고 할 때 JAR 내의 내 서블릿이 다시 인식되지 않습니다. 주어진 예외를 던집니다.ANT를 사용하여 작성된 JAR을 실행하는 중에 문제가 발생했습니다.

javax.servlet.ServletException: Wrapper cannot find servlet class my.hello.servlet.WelcomeServlet or a class it depends on 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) 
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) 
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
    java.lang.Thread.run(Unknown Source) 
root cause 

java.lang.ClassNotFoundException: my.hello.servlet.WelcomeServlet 
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) 
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) 
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) 
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
    java.lang.Thread.run(Unknown Source) 

누군가 내 서블릿 클래스가 재 인증받지 못하는 이유를 알려주십시오.

내 디렉토리 구조는

MyFirstApp 
    | 
    --WEB_INF 
     | 
      -- lib 
       | 
       -- all external jars and the jar containing the class files of my app 
     | 
      -- web.xml 
    | 
     -- index.jsp 
    | 
     -- welcome.jsp 

내 build.xml 파일은 이클립스를 사용하여 JAR를 만드는 시도

<project name="MyFirstApp" default="jar" basedir=".."> 
    <property name="src" location="/shil/JAVA/Spring Workspace/myfirstapp1/src"/> 
    <property name="build" location="build"/> 
    <property name="lib" location="/shil/JAVA/Spring Workspace/myfirstapp1/WebContent/WEB-INF/lib"/>   
    <path id="classpath-example"> 
     <fileset dir="${lib}" includes="*.jar"/> 
    </path>  
    <target name="clean"> 
     <delete dir="${build}"/> 
    </target> 
    <target name="init" depends="clean"> 
     <echo>Creating the build directory</echo> 
     <!---<mkdir dir="build/jar"/> 
     <mkdir dir="build/my/hello"/>     
     <mkdir dir="build/my/hello/servlet"/>-->  
     <mkdir dir="build/classes"/>  
    </target> 
    <target name="compile" depends="init"> 
     <echo>compiling</echo> 
     <!---<mkdir dir="build/classes"/>-->   
     <javac srcdir="${src}" destdir="build/classes"    includeantruntime="false"> 
      <classpath refid="classpath-example"/> 
     </javac> 
    </target> 
    <target name="jar" depends="compile"> 
     <echo>building the jar</echo>  
     <jar destfile="F:/shil/JAVA/Spring Workspace/myfirstapp1/ant/helloworld.jar"       basedir="build"/>   
    </target> 
    <target name="run" depends="jar"> 
     <echo>running the jar</echo> 
     <java jar="F:/shil/JAVA/Spring Workspace/myfirstapp1/ant/helloworld.jar" fork="true"/> 
    </target> 
</project> 

입니다. 또한 오류가 발생합니다.

JAR creation failed. See details for additional information. 
    Exported with compile warnings: myfirstapp1/src/my/hello/HelloWorldApp.java 
    Could not find source file attribute for: 'F:\shil\JAVA\Spring Workspace\myfirstapp1\build\classes\my\hello\HelloWorldApp.class' 
    Source name not found in a class file - exported all class files in myfirstapp1/build/classes/my/hello 
    Resource is out of sync with the file system: '/myfirstapp1/build/classes/my/hello/HelloWorldApp.class'. 
    Resource is out of sync with the file system: '/myfirstapp1/build/classes/my/hello/MyTime.class'. 
    Resource is out of sync with the file system: '/myfirstapp1/build/classes/my/hello/SayHello.class'. 
    Could not find source file attribute for: 'F:\shil\JAVA\Spring Workspace\myfirstapp1\build\classes\my\hello\servlet\HelloWorldServlet.class' 
    Source name not found in a class file - exported all class files in myfirstapp1/build/classes/my/hello/servlet 
    Resource is out of sync with the file system: '/myfirstapp1/build/classes/my/hello/servlet/HelloWorldServlet.class'. 
    Resource is out of sync with the file system: '/myfirstapp1/build/classes/my/hello/servlet/WelcomeServlet.class'. 

누군가 도와 줄 수 있습니까?

이것은 병 구조입니다. 그것은 compile 대상에 destdir 일치 있도록 jar 대상에서

helloworld.jar 
    | 
     -- META-INF 
      | 
      -- MANIFEST.MF 
    | 
     -- my 
      | 
      -- hello 
       | 
       -- HelloWorldApp.class 
       | 
       -- MyTime.class 
       | 
       -- SayHello.class 
       | 
       -- servlet 
         | 
         -- HelloWorldServlet.class 
         | 
         -- WelcomeServlet.class 
+0

일부 폴더에 클래스의 추가 줄 바꿈이없는 경우 병 구조를 확인하십시오. – Santosh

답변

0

, 대신 "build"basedir="build/classes"을 시도합니다.

JAR이 있어야하는 위의 한 디렉토리에서 빌드 된 것으로 보이므로 클래스에 대한 내부 경로가 잘못되어 클래스 로더가 해당 경로를 찾을 수 없습니다.

+0

나는 그 일을 너무 많이 시도했다. 여전히 작동하지 않는다. ( – meenakshi

0

tomcat을 다시 시작하기 전에 {tomcat_home}/work 폴더 내의 폴더를 삭제 해보십시오.

+0

/tomcat_home/work 폴더가 비어있다. 여전히 작동하지 않는다 !! – meenakshi

+0

jar 파일의 압축을 풀고 클래스가 올바르게 구성되어 있는지 확인할 수 있습니까? – Santosh

관련 문제