0
votes

I am using Maven for building a Spring project. For testing it in local, I am using jetty:run goal. (maven jetty plugin)

When I execute it, I get:

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/ is in my WEB.xml file, like that:

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

app.server.context is replaced by maven when building(verified that).

There is no problem when I deploy my war in tomcat or run jetty:run-exploded I guess the problem is that maven can't resolve /WEB-INF/classes/db/ when running from unpackaged resources. How can I make it resolve it?

Here is my maven config for jetty plugin:

..
..
<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>
..
..
1

1 Answers

0
votes

Ok, I finally understood the problem. I thought jetty is somewhat searching (jetty:run goal)

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

or

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

for the web.xml config

<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>

However, I somewhat realized it was searching

{Workspace}/MyApplication/target/classes

which was Eclipse project output folder & did not contain db folder (I somewhat excluded it for that output folder, WAR already contains it.)

So I got rid of that exclude, and everything is fine.