【问题标题】:Web.xml can't resolve URI when run with maven jetty:run使用 maven jetty:run 运行时,Web.xml 无法解析 URI
【发布时间】:2014-04-19 13:42:19
【问题描述】:

我正在使用 Maven 构建一个 Spring 项目。 为了在本地测试它,我使用 jetty:run 目标。 (maven 码头插件)

当我执行它时,我得到:

Caused by: 
java.io.FileNotFoundException: ServletContext resource [/WEB-INF/classes/db/] 
cannot be resolved to URL because it does not exist
at     
org.springframework.web.context.support.ServletContextResource.getURL
(ServletContextResource.java:154)

/WEB-INF/classes/db/ 在我的 WEB.xml 文件中,像这样:

/WEB-INF/classes/db/${app.server.context}

app.server.context 在构建时被 maven 替换(验证)。

当我在tomcat中部署我的war或运行jetty时没有问题:run-exploded 我想问题是从未打包的资源运行时,maven 无法解析 /WEB-INF/classes/db/ 。我怎样才能让它解决它?

这是我的码头插件的 Maven 配置:

..
..
<plugin>


<!-- http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin -->
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
<!--                    <scanIntervalSeconds>10</scanIntervalSeconds> -->

<classesDirectory>${basedir}/target/classes</classesDirectory>
 <scanIntervalSeconds>10</scanIntervalSeconds>
                    <war>${basedir}/target</war>
                    <webAppConfig>
                        <descriptor>${basedir}/target/MyApplication/WEB-INF/web.xml</descriptor>
                        <contextPath>${application.contextpath}</contextPath>
                        <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
                    </webAppConfig>
                    <connectors>
                        <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                            <port>${application.port}</port>
                        </connector>
                    </connectors>
                    <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
                        <filename>${project.build.directory}/jetty-yyyy_mm_dd-request.log
                        </filename>
                        <retainDays>3</retainDays>
                        <append>true</append>
                        <extended>false</extended>
                        <logTimeZone>GMT</logTimeZone>
                    </requestLog>
                </configuration>
            </plugin>
..
..

【问题讨论】:

    标签: maven jetty


    【解决方案1】:

    好的,我终于明白了这个问题。 我以为码头有点搜索(码头:运行目标)

    {Workspace}/MyApplication/src/main/webapp/WEB-INF/classes/db

    {Workspace}/MyApplication/target/MyApplication/WEB-INF/classes/db

    用于 web.xml 配置

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/classes/db/*Context_Tomcat.xml
            /WEB-INF/classes/*Context.xml
        </param-value>
    </context-param>
    

    然而, 我有点意识到它在搜索

    {Workspace}/MyApplication/target/classes
    

    这是 Eclipse 项目输出文件夹,不包含 db 文件夹(我在某种程度上排除了该输出文件夹,WAR 已经包含它。)

    所以我摆脱了那个排除,一切都很好。

    【讨论】:

      猜你喜欢
      • 2015-11-16
      • 2010-11-14
      • 2018-07-03
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      • 2011-10-10
      • 2017-10-17
      • 2019-07-05
      相关资源
      最近更新 更多