maven-2 - 使用 Maven Jetty 插件部署 war 时获取 FileNotFoundException

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

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

java.io.FileNotFoundException: Could not open ServletContext resource [/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::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)

感谢您的建议。

最佳答案

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

关于maven-2 - 使用 Maven Jetty 插件部署 war 时获取 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6947720/

相关文章:

使用 fluidd 导出 Java 日志记录

gradle - 生成项目 : HUGE downloads

java - Maven eclipse 不添加依赖

java - 在 JVM 启动时从 .jar 中的 .properties 文件设置属性

java - IntelliJ 运行带有 @Ignore 注释的 Kotlin 测试

Spring Boot与Angular(五)项目结构

java - 在项目 xxx 的构建路径中检测到循环 - 构建路径问题

java - 在 java 应用程序中嵌入 Apache stanbol(Maven)

java - Jetty TLS 1.0 和客户端 TLS 1.2

java - jetty :如何声明 JVM 范围内的 jndi 条目并绑定(bind)到 java:comp/env