使用 Maven Jetty 插件部署 war 时出现 FileNotFoundException
我使用 Maven 3.0.3 和 Jetty 插件。我收到以下错误:
java.io.FileNotFoundException:无法打开 ServletContext 资源 [/WEB-INF/applicationContext.xml
我不明白,因为该文件存在于 target/mywar/WEB-INF/applicationContext.xml
中。我在我的 web.xml
中调用这个文件:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4">
<display-name>/jx-production-1.0-SNAPSHOT</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>Any ideas what I'm missing? Here is my Jetty plugin definition in my pom.xml …
<profile>
<id>jetty</id>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.2.v20101205</version>
<configuration>
<webAppConfig>
<contextPath>/all-new-jx</contextPath>
<descriptor>target/jx-1.0-SNAPSHOT/WEB-INF/web.xml</descriptor>
</webAppConfig>
<jettyConfig>config/jetty7/jetty.xml</jettyConfig>
<scanIntervalSeconds>10</scanIntervalSeconds>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.server.handler.ContextHandler">
<contextPath>/all-new-jx-web</contextPath>
<resourceBase>${project.basedir}/target/web</resourceBase>
<handler implementation="org.eclipse.jetty.server.handler.ResourceHandler" />
</contextHandler>
</contextHandlers>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-rewrite</artifactId>
<version>7.2.2.v20101205</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
这是我遇到的又长又讨厌的错误:
2011-08-04 14:08:56.677:WARN::上下文启动失败 omjpJettyWebAppContext{/all-new-jx,文件:/Users/davea/Documents/workspace/NissanUSA2/Technology/nna/mycousa/jx/src/main/webapp/},文件:/Users/davea/Documents/workspace/NissanUSA2 /技术/nna/mycouusa/jx/src/main/webapp/ org.springframework.beans.factory.BeanDefinitionStoreException: 从 ServletContext 资源解析 XML 文档时发生 IOException [/WEB-INF/applicationContext.xml];嵌套异常是 java.io.FileNotFoundException:无法打开 ServletContext 资源 [/WEB-INF/applicationContext.xml] 位于 org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:641) 在 org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:228) 在 org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1181) 在 org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:584) 在 org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:496) 在 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226) 在 org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:164) 在 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226) 在 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93) 在 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93) 在 org.eclipse.jetty.server.Server.doStart(Server.java:243) 处 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 在 org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 在 org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 在 org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) 处 org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 在 org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 在 org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 位于 org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 位于 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) 在 org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) 在 org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) 造成原因: java.io.FileNotFoundException:无法打开 ServletContext 资源 [/WEB-INF/applicationContext.xml] org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:641) 在 org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:228) 在 org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1181) 在 org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:584) 在 org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:496) 在 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226) 在 org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:164) 在 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226) 在 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93) 在 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93) 在 org.eclipse.jetty.server.Server.doStart(Server.java:243) 处 org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 在 org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 在 org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 在 org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 在 org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) 处 org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 在 org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 在 org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 位于 org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 位于 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) 在 org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) 在 org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
感谢您的建议。
I'm using Maven 3.0.3 with the Jetty plugin. I'm getting the error below:
java.io.FileNotFoundException: Could not open ServletContext resource
[/WEB-INF/applicationContext.xml
which I don't understand, because the file is present at target/mywar/WEB-INF/applicationContext.xml
. I call this file in my web.xml
:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4">
<display-name>/jx-production-1.0-SNAPSHOT</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>Any ideas what I'm missing? Here is my Jetty plugin definition in my pom.xml …
<profile>
<id>jetty</id>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.2.v20101205</version>
<configuration>
<webAppConfig>
<contextPath>/all-new-jx</contextPath>
<descriptor>target/jx-1.0-SNAPSHOT/WEB-INF/web.xml</descriptor>
</webAppConfig>
<jettyConfig>config/jetty7/jetty.xml</jettyConfig>
<scanIntervalSeconds>10</scanIntervalSeconds>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.server.handler.ContextHandler">
<contextPath>/all-new-jx-web</contextPath>
<resourceBase>${project.basedir}/target/web</resourceBase>
<handler implementation="org.eclipse.jetty.server.handler.ResourceHandler" />
</contextHandler>
</contextHandlers>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-rewrite</artifactId>
<version>7.2.2.v20101205</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
Here's the long, nasty error I'm getting:
2011-08-04 14:08:56.677:WARN::Failed startup of context
o.m.j.p.JettyWebAppContext{/all-new-jx,file:/Users/davea/Documents/workspace/NissanUSA2/Technology/nna/mycousa/jx/src/main/webapp/},file:/Users/davea/Documents/workspace/NissanUSA2/Technology/nna/mycousa/jx/src/main/webapp/
org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from ServletContext resource
[/WEB-INF/applicationContext.xml]; nested exception is
java.io.FileNotFoundException: Could not open ServletContext resource
[/WEB-INF/applicationContext.xml] at
org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:641)
at
org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:228)
at
org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1181)
at
org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:584)
at
org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:496)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226)
at
org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:164)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93)
at org.eclipse.jetty.server.Server.doStart(Server.java:243) at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at
org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at
org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) at
org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at
org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at
org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at
org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at
org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by:
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml] at
org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:641)
at
org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:228)
at
org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1181)
at
org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:584)
at
org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:496)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226)
at
org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:164)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93)
at org.eclipse.jetty.server.Server.doStart(Server.java:243) at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at
org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at
org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) at
org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at
org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at
org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at
org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at
org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Thanks for your advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在使用运行目标 - 即
mvn jetty:run
?它“就地”运行 web 应用程序,这意味着它会在target/classes
或项目依赖项中查找类,并从src/main/webapp
加载 Web 资源(假设默认目录布局)。它不会在target/mywar/...
中找到任何内容。您可以使用其他 jetty 插件目标之一,但我会建议将 applicationContext.xml 移至类路径中,并使用classpath:/applicationContext.xml
作为contextConfigLocation
。I assume you're using the run goal--i.e.
mvn jetty:run
? That runs a webapp "in place", meaning it looks for classes intarget/classes
or in your project dependencies, and it loads web resources fromsrc/main/webapp
(assuming default directory layout). It won't find anything intarget/mywar/...
. You could use one of the other jetty plugin goals, but I'd recommend just moving your applicationContext.xml into the classpath and usingclasspath:/applicationContext.xml
as yourcontextConfigLocation
.