2011-09-17 6 views
1

hello world app用の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は、私はEclipseを使用して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'. 

誰かが助けてくれますか?

これは、瓶の構造です。あなたのjarターゲットで

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

いくつかのフォルダにクラスの追加ラッピングがない場合は、jar構造をチェックしてください。 – Santosh

答えて

0

それはcompileターゲットにdestdirと一致するように、だけではなく"build"basedir="build/classes"を試してみてください。

JARがあるべき場所の上にある1つのディレクトリからビルドされているようです。そのため、クラスへの内部パスが正しくなく、クラスローダーがそれらを見つけることができません。

+0

私はそれもやってみました..まだ動作していません:( – meenakshi

0

また、tomcatを再起動する前に{tomcat_home}/workフォルダ内のフォルダを削除してみてください。

+0

{tomcat_home}/workフォルダーが空ですまだ動作しません!! – meenakshi

+0

jarを解凍してクラスが正しく構成されているかどうか確認できますか? – Santosh

関連する問題