1

I am new to maven web application, below is my eclipse directory..

MyProject
-- src
------main
----------resources
-------------------images
--------------------------myimage.png
----------webapp
----------------index.html
----------WEB-INF
----------------web.xml

Here is my index.html source.

<img alt="" src="images/myimage.png">

When I run this image is not shown in browser. I heard somewhere we should declare/map the resource directory in web.xml file but I did not found anything.

I have tried every possible ways in img src path.

I just need to show the image in my html page.

Can anybody help..

S. Das
  • 75
  • 3
  • 9

3 Answers3

1

basic-maven-project:

 |-- pom.xml
 |-- src
 |   |-- main
 |   |   |-- java
 |   |   |-- resources -- Images folder under here.
 |   |   `-- webapp

 |   |       `-- WEB-INF
 |   `-- test

 |       |-- java

 |       `-- resources
    `-- target
 |-- classes
   `-- test-classes

Try:

<img alt="" src="resources/images/myimage.png">

For a more thorough description see the answer to this SO question :Here and How to pack resources in a Maven Project?.

Community
  • 1
  • 1
Perdomoff
  • 938
  • 2
  • 7
  • 26
1

As described on the usage page of the maven-war-plugin, you should put those files under src/main/webapp. Only if you need images on the classpath (which is not the case), you should put them under src/main/resources

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
0

you can use the code in jsp as:

<img id="ctl01_imgCOESign" src="<%=URI.create(request.getRequestURL().toString()).resolve(request.getContextPath())%>/images/coesign.jpg">