【问题标题】:Getting FileNotFoundException when deploying war using Maven Jetty plugin使用 Maven Jetty 插件部署战争时出现 FileNotFoundException
【发布时间】:2011-10-20 08:03:00
【问题描述】:

我正在使用带有 Jetty 插件的 Maven 3.0.3。我收到以下错误:

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,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 从 ServletContext 资源解析 XML 文档 [/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)

感谢您的建议。

【问题讨论】:

    标签: maven-2 maven jetty embedded-jetty maven-jetty-plugin


    【解决方案1】:

    我假设您正在使用运行目标 - 即mvn jetty:run?这会“就地”运行一个 webapp,这意味着它会在 target/classes 或您的项目依赖项中查找类,并从 src/main/webapp 加载 Web 资源(假设默认目录布局)。它不会在target/mywar/... 中找到任何内容。您可以使用其他 jetty plugin goals 之一,但我建议您将 applicationContext.xml 移动到类路径中并使用 classpath:/applicationContext.xml 作为您的 contextConfigLocation

    【讨论】:

    • 是的,我正在使用目标码头:运行并将必要的资源复制到 src/main/webapp 工作,非常感谢您的解释。
    • jetty 插件目标链接在 codehaus 移动后不再有效
    猜你喜欢
    • 2014-08-20
    • 1970-01-01
    • 2014-01-19
    • 2013-12-27
    • 2012-12-28
    • 1970-01-01
    • 2014-04-23
    • 2015-09-30
    • 2015-12-30
    相关资源
    最近更新 更多