我正在使用spring mvc和hibernate创建一个Web应用程序,我从tomcat 7控制台输出中得到一个非常奇怪的错误,说明:
13-Sep-2010 08:27:18 org.apache.catalina.startup.HostConfig checkResources INFO: Undeploying context [/ZangV3Spring]
13-Sep-2010 08:27:18 org.apache.catalina.startup.HostConfig deployWAR INFO: Deploying web application archive ZangV3Spring.war
13-Sep-2010 08:27:20 org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(C:\Users\xxxxx\Various stuff\apache-tomcat-7.0.0-windows-x86\apache-tomcat-7.0.0\webapps\ZangV3Spring\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
13-Sep-2010 08:27:21 org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerStart
13-Sep-2010 08:27:21 org.apache.catalina.core.StandardContext startInternal SEVERE: Context [/ZangV3Spring] startup failed due to previous errors
如何修复此错误?
这是我的build.xml:
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="ZangV3Spring"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<!-- We need the servlet API classes: -->
<!-- * for Tomcat 5/6 use servlet-api.jar -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="servlet*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="usage">
<echo message=""/>
<echo message="${name} build file"/>
<echo message="-----------------------------------"/>
<echo message=""/>
<echo message="Available targets are:"/>
<echo message=""/>
<echo message="build --> Build the application"/>
<echo message="deploy --> Deploy application as directory"/>
<echo message="deploywar --> Deploy application as a WAR file"/>
<echo message="install --> Install application in Tomcat"/>
<echo message="reload --> Reload application in Tomcat"/>
<echo message="start --> Start Tomcat application"/>
<echo message="stop --> Stop Tomcat application"/>
<echo message="list --> List Tomcat applications"/>
<echo message=""/>
</target>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="deploy" depends="build" description="Deploy application">
<copy todir="${deploy.path}/${name}" preservelastmodified="true">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
<target name="deploywar" depends="build" description="Deploy application as a WAR file">
<war destfile="${deploy.path}/${name}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<path id="catalina-ant-classpath">
<!-- We need the Catalina jars for Tomcat -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"/>
</fileset>
</path>
<taskdef name="install" classname="org.apache.catalina.ant.DeployTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<target name="install" description="Install application in Tomcat">
<install url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"
war="${name}"/>
</target>
<target name="reload" description="Reload application in Tomcat">
<reload url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="start" description="Start Tomcat application">
<start url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="stop" description="Stop Tomcat application">
<stop url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="list" description="List Tomcat applications">
<list url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"/>
</target>
以下是我的build.properties文件:
# Ant properties for building the springapp
appserver.home=C:/Users/xxxxx/Various stuff/apache-tomcat-7.0.0-windows-x86/apache-tomcat-7.0.0/
# for Tomcat 5 use $appserver.home}/server/lib
# for Tomcat 6 use $appserver.home}/lib
appserver.lib=${appserver.home}/lib/
deploy.path=${appserver.home}/webapps
tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=
tomcat.manager.password=
这是我的lib文件夹:
答案 0 :(得分:0)
如果我删除了servlett-api.jar文件,它将不会像我用来引用servlet中断的任何代码一样构建或编译。
示例是我不能再使用它了:
import javax.servlet.http.HttpServletRequest;
this is the error im getting now [QUOTE]13-Sep-2010 12:22:45 org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive ZangV3Spring.war
13-Sep-2010 12:22:49 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
13-Sep-2010 12:22:49 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/ZangV3Spring] startup failed due to previous errors
13-Sep-2010 12:22:49 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/ZangV3Spring] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
13-Sep-2010 12:22:59 org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/ZangV3Spring]
13-Sep-2010 12:22:59 org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive ZangV3Spring.war
13-Sep-2010 12:23:03 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
13-Sep-2010 12:23:03 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/ZangV3Spring] startup failed due to previous errors
这就是我的web.xml的样子
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- -->
<!-- Register and setup my servlet xml files here -->
<servlet>
<servlet-name>appStore</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>appStore</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/zang-file-service.xml
</param-value>
</context-param>
</web-app>
答案 1 :(得分:0)
在我的情况下,unpackWAR="false"
中的unpackWAR="true"
更改为META-INF/context.xml
完成了这项工作。
答案 2 :(得分:0)
检查您的库中是否包含servlet-api.jar。如果没有添加它。 Also check if this solution solves your problem