LostMohican
LostMohican

Reputation: 3144

maven: cannot load images/css/js in tomcat application

I'm new to maven and we are developing a Spring application with maven3. We are having a problem with maven web application web resources, we cannot load any resources within our application. After I deploy the application to tomcat, i can see the files the application needs, but when the application tries to load them for example as an image, it cannot load the image.

In my webapp folder I have this directory structure:

-rw-r--r-- 1 erkin.unlu domain users  360 Sep 18 11:54 index.jsp
drwxr-xr-x 2 erkin.unlu domain users 4096 Sep 18 11:54 resources/
drwxr-xr-x 3 erkin.unlu domain users 4096 Sep 18 11:54 WEB-INF/

there is a magni.png in resources folder.

After deploying the application, project folder looks below in tomcat/webapps:

-rw-r--r-- 1 erkin.unlu domain users  360 Sep 18 11:54 index.jsp
-rw-r--r-- 1 erkin.unlu domain users  518 Sep 18 11:06 magni.png
drwxr-xr-x 3 erkin.unlu domain users 4096 Sep 18 11:54 META-INF/
drwxr-xr-x 2 erkin.unlu domain users 4096 Sep 18 11:54 resources/
drwxr-xr-x 5 erkin.unlu domain users 4096 Sep 18 11:54 WEB-INF/

But even though I can see the index.jsp from a browser, when I want to see magni.png, I get 404 error from Tomcat.

There is a similar project which uses ant, and we dont have this problem on that project.

By the way my pom.xml's has a war plugin like below :

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp/resources</directory>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

So what is the reason for this behaviour? Am I missing some default configurations of maven or Tomcat?

Upvotes: 0

Views: 1219

Answers (1)

arulraj.net
arulraj.net

Reputation: 4837

Any file outside WEB-INF folder can access directly like below. There is no authentication required

http://localhost:8080/project/magni.png

Seems to be tomcat or permission issue. Maven is just building tool.

Upvotes: 2

Related Questions