S. Das
S. Das

Reputation: 75

Can't access image from html page in maven

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..

Upvotes: 1

Views: 3374

Answers (3)

shivanshu dixit
shivanshu dixit

Reputation: 71

you can use the code in jsp as:

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

Upvotes: 0

Robert Scholte
Robert Scholte

Reputation: 12345

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

Upvotes: 1

Perdomoff
Perdomoff

Reputation: 957

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?.

Upvotes: 1

Related Questions