problem while executing the JAR written using ANT
I have written a simple hello world app using Spring and an ANT script to generate JAR file for the hello world app. The JAR is getting generated and the classes are getting compiled properly. I then copied the JAR into my tomcat webapps folder, started tomcat and loaded the index.jsp page. When i tried to navigate from the index.jsp page my Servlet inside the JAR is not getting recogonized. it throws the below given exception.
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.loadCla开发者_如何转开发ss(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)
can someone please tell me why my Servlet class is not getting recogonized?
my directory structure is
MyFirstApp
|
--WEB_INF
|
-- lib
|
-- all external jars and the jar containing the class files of my app
|
-- web.xml
|
-- index.jsp
|
-- welcome.jsp
my build.xml is
<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>
i tried creating JAR using eclipse. This also gives errors.
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'.
can someone help, please?
this is the structure of the jar.
helloworld.jar
|
-- META-INF
|
-- MANIFEST.MF
|
-- my
|
-- hello
|
-- HelloWorldApp.class
|
-- MyTime.class
|
-- SayHello.class
|
-- servlet
|
-- HelloWorldServlet.class
|
-- WelcomeServlet.class
In your jar
target, try basedir="build/classes"
instead of just "build"
, so that it matches the destdir
in the compile
target.
It looks like the JAR is being built from one directory above where it should be, so the internal paths to the classes are incorrect and the classloader can't find them.
Please also try delete the folders inside {tomcat_home}/work folder before you restart the tomcat.
精彩评论