Get Eclipse for recognizing CSS included via context in a Spring MVC project

I read many different ways to incorporate CSS into a Spring MVC project, and they all load fine when deployed to a server:

<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet"> <link href="<c:url value='/css/style.css' />" rel="stylesheet"> <link href="/MyApp/css/style.css" rel="stylesheet"> 

However, it seems that Eclipse is not too happy if I did not provide a relative path (for example ../../css/style.css ../ ../../css/style.css ), but this path will obviously not load during deployment. If I use one of the three methods above, I get a red wavy line below the path with the error:

 Undefined CSS file ("${pageContext.request.contextPath}/css/style.css"). 

All classes used from this stylesheet will also have a similar error:

 Undefined CSS class (class-name). 

Am I missing something or do I need to live with it and turn off warnings?

+4
spring eclipse css spring-mvc
source share
2 answers

I also experienced this problem and found that the error was detected in the Eclipse WTP Webresources project on githib:

https://github.com/angelozerr/eclipse-wtp-webresources/issues/37

If / When this is fixed, our annoying red curved lines will be a thing of the past!

+1
source share

I refused to find the perfect answer and instead restructured my project so that the relative path of the physical files reflected the logical path when the application was deployed. Makes your choice of structure a little tough, but at least it satisfies development conditions and runtime.

Final answer:

 <link href="../css/style.css" rel="stylesheet"> 
0
source share

All Articles