I have asked another question related to this in this thread Where to put css resources in a maven project
thinking that I was not putting the css resources under the right location in a Maven project structure. Right now I have a folder under webapp called css and I have the css resources there. My problem is that when I do mvn clean tomcat:run those css resources do not seem to be picked up and put appropriately in the target folder so my application cannot pick them up.
Does anybody know why?
UPDATE
My goal is to avoid building the war upon deployment for rapid development.I have changed my Maven command to: mvn clean war:exploded tomcat:run
The application runs fine but the css is not being picked up. If I go to the browser and type: http://localhost:8080/appname/css/styles.css
I get a Spring Framework error saying No mapping found for HTTP request with URI [/appname/css/styles.css in DispatcherServlet
In other Spring Java apps that I have built using traditional project style (not maven) I was able to access the css from the borwser with the url above. I have made sure that the css folder is hanging straight out of the webapp folder.
Any ideas?
UPDATE: Adding web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml
classpath*:META-INF/spring/applicationContext*.xml
</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I do not have the Dispatcher servlet mapped to /* and it still tries to access CSS files through the DispatcherServlet.
tomcat:runuse thesrcfolder, not thetarget. Yourcssfiles are in a good place insrc/main/webapp/css. They should be available from a browser.mvn -X tomcat:runprints the configuration. Some interesting parts:You can find some more details in this answer: mvn tomcat7:run – How does it work?
For the second question/update: I think you mapped a Spring servlet to
/*and it does not handle static content. Post yourweb.xmland Spring configuration. Maybe you just need amvc:resourcesinto your Spring configuration. This also could be useful: How to handle static content in Spring MVC?