Ascalonian Ascalonian - 2 years ago 104
Java Question

Spring MVC project missing images & styles when deploying in Eclipse to Tomcat

I have a Spring MVC project in Eclipse. Maven packages it as a WAR and then I have it deployed to Tomcat through Eclipse. The issue I am running into is that the

and the
folders in the /webapp folder are not coming through. The page will generate and the Spring MVC functionality works (calls the Controller, etc). However, none of the styling will appear. I would greatly appreciate any help getting this to work.


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns="" xsi:schemaLocation="" id="WebApp_ID" version="2.5">
<display-name>Some Project</display-name>






<beans xmlns=""

<context:component-scan base-package="" />

<bean id="messageSource" class="">
<property name="basename" value="classpath:messages" />
<property name="cacheSeconds" value="60" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />

<!-- Need this to handle multipart files -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

<bean class="" />
<bean class="" />

pom.xml (parts of it

<!-- The Build -->
<!-- using Hibernate 4.3.11.Final -->


<link rel="stylesheet" type="text/css" media="all" href="/styles/screen.css" />
<link rel="stylesheet" type="text/css" media="print" href="/styles/print.css" />
<link rel="stylesheet" type="text/css" href="/styles/jquery/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="/styles/roper-center.css">
<link rel="stylesheet" type="text/css" href="/styles/font-awesome-4.5.0/css/font-awesome.css">

<script src="js/modernizr.js"></script>
<script src="js/framework/iws.js"></script>
<script src="js/sorttable.js"></script>
<script src="js/jquery/jquery-1.12.2.min.js"></script>
<script src="js/jquery/external/jquery/jquery.js"></script>
<script src="js/jquery/jquery-ui.js"></script>
<script src="js/jquery/jquery.autotab.js"></script>

As you can see above, I tried putting a
before the styles and did not put them in the "js" part. I viewed the page source of the page and clicked on the link for both and Tomcat comes back saying it can't find either.

If I look into the deployment folder (/opt/apache-tomcat-8.0.32/webapps/some-project), I see the following folders:






And here is my
folder in Eclipse:

webapps folder list

And in case, here is my Deployment Assembly

enter image description here

Answer Source

I don't have much experience when it comes to xml spring configurations. But when I look at one project I have I find the following configurations for my resources. Note my file structure is like yours as well.

<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources location="/js/" mapping="/js/**" />
<mvc:annotation-driven />

I have that in the same file where I declare my InternalResourceViewResolver. Hope it helps.

The complete file:

<beans xmlns=""
    xmlns:mvc="" xmlns:context=""
    xsi:schemaLocation="    ">

    <context:component-scan base-package="" />

    <!-- Internal (final) resolver -->
        <property name="prefix">
        <property name="suffix">
        <property name="order">

    <mvc:resources mapping="/css/**" location="/css/" />
    <mvc:resources mapping="/images/**" location="/images/" />
    <mvc:resources location="/js/" mapping="/js/**" />
    <mvc:annotation-driven />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download