2

after reading various questions about how to handle images on tomcat I followed the approach to set a folder with images at tomcat following the instructions here: Simplest way to serve static data from outside the application server in a Java web application but it doesn't work and I cannot understand what I am doing wrong.

I've set the context in server.xml as described:

 <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">



    <Context docBase="C:\ServerFiles\" path="/images" />


        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>

and I also tried this:

    <Context docBase="C:\ServerFiles" path="/images" />

instead of the above.

The image is located at

C:\ServerFiles and its name is index.jpg

and this is how i try to retrieve it with jsf

<img src="/images/index.jpg" />

but it doens't work

Can you help me? I cannot understand what I am doing wrong.

Community
  • 1
  • 1
JmRag
  • 1,443
  • 7
  • 19
  • 56
  • Are you using an IDE capable of taking over control from server, like Eclipse? If so, then you should be editing `server.xml` file in IDE's *Servers* project instead. Otherwise, you need to reconfigure the IDE to not take over control from server, but just use it directly (including all of its configuration files which you edited externally outside control of the IDE). – BalusC Aug 25 '14 at 19:45
  • @BalusC I didn't know that. I am using eclipse which does what you say. So I should edit the file at the servers->Server-name->server.xml right? I am just curious I've edited the server.xml at the config folder of the ApacheTomcat in order to support https and it worked fine, though I didn't edited the server.xml at the eclipse. Aren't those two equivalent? – JmRag Aug 25 '14 at 19:55
  • Both ways of editing server.xml are correct. If I understand it correctly if you modify the config folder inside tomcat, the changes are global, whereas your changes to eclipse's server.xml only affect the embedded tomcat in the IDE. – pacman Aug 25 '14 at 20:03
  • @BalusC you are right, I changed it in the server.xml of the eclipse and it worked. Perfectly. – JmRag Aug 25 '14 at 22:58
  • You apparently changed to HTTPS before adding the server in Eclipse. Eclipse basically creates a copy of the "current" config. I'll post an answer. – BalusC Aug 26 '14 at 04:54

2 Answers2

1

If editing Tomcat's server.xml (or context.xml or web.xml or what not which resides in its /conf folder) appears to have no effect, then it's a strong hint that you're using an IDE which has taken over the control from Tomcat. Eclipse for example does that by default. When you add Tomcat server in Eclipse, then it basically creates a copy of its /conf folder into the IDE's Servers project, uses the IDE workspace as deploy space and solely uses Tomcat server's engine to run projects against the config in Servers project and deployments inside workspace.

You have basically 2 options:

  1. Edit the configuration files in Servers project instead.

  2. Tell Eclipse to not take over control from Tomcat but instead use (and manipulate!) it directly. Doubleclick the Tomcat entry in Servers view, select in the section Server location the option Use Tomcat installation.

    enter image description here

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
-1

The way you've defined Context should work. I cross checked a project where I do this and I didn't see any issue on your server.xml.

Maybe you have a separate context.xml in the METAINF folder of your web module that overrides the setting here.

BTW the second example without the trailing \ is the correct way to do it.

pacman
  • 1,061
  • 1
  • 17
  • 36
  • No, the META-INF exists only a file named MANIFEST.MF – JmRag Aug 25 '14 at 19:58
  • 1
    Hmm.. Can you try accessing your index.jpg by fully qualifying it.. I mean with the whole server name etc and see if you can access it.. – pacman Aug 25 '14 at 20:00