Rahul Kumar
Rahul Kumar

Reputation: 399

CSS and JS file loactions in a maven project

I a currently working on a maven project on eclipse , my HTML , css , js and jsp files are under

webapp
    |
     WEB-INF
           |
            css/style.css
            js/myjs.js
            index.jsp
            index1.html

My webapp cannot seem to access the CSS and JS, I keep getting the following error in Chrome for my CSS, img, and JS files:

GET "URL....................css" 404 (Not Found)                      friend:5

I have seen a lot of questions related to this, but none of the solution seems to work. Any help would be appreciated!

Upvotes: 2

Views: 6438

Answers (2)

yathirigan
yathirigan

Reputation: 6059

point 1: Move your web content files (html/jsp/js/css) out of web-inf, create respective folders directly under webapp.

point 2: pls share the code snippet of how you are referring to the image or js or css from your HTML/JSP page.

E.g. In the below folder structure the image/css/js resources are referred in html/jsp as

 webapp
   |
   |__ pages
   |    |___ index.jsp
   |    |___ index.html
   |
   |__ css
   |    |___ style.css
   |    
   |__ js
   |    |___ myjs.js


Upvotes: 3

machineghost
machineghost

Reputation: 35760

That error is basically saying "the file is not there!". The thing is, whether the files are there or not has nothing to do with Maven (or Tomcat or whatever); it's all controlled by your webserver (which is likely Apache). Assuming it is Apache, you'll want to look at your config to see what the DocumentRoot is set to, as that's where where static files are served from (although Apache config can get more complex than that so it really depends on your particulars).

The general thing to understand though is that just throwing things in WEB-INF doesn't inherently expose them to the world: you need to have the files exposed via Apache.

Upvotes: 2

Related Questions