[ACCEPTED]-Mapping a directory outside the web-app to URL in TOMCAT-jakarta-ee

Accepted answer
Score: 35

Add a <Context> tag in server.xml, inside 2 the <Host> tag:

<Context path="/images" docBase="C:/test/images/" />

Docs will be accessible 1 at http://localhost:8080/images

Score: 5

in Tomcat8 you can also add PotsResources 1 to you META-INF/context.xml as follow :

<Context>
    <Resources allowLinking="false">
        <PostResources readOnly="false"
                       className="org.apache.catalina.webresources.DirResourceSet"
                       base="path-to-your-local-folder"
                       webAppMount="/images"/>
    </Resources>

    ...
</Context>
Score: 4

I had the same issue but found a solution.

If 10 you are using Eclipse and a Tomcat plugin 9 then please note that the Eclipse Tomcat 8 plugin creates a separate CATALINA_BASE under the Eclipse 7 workspace directory.

You can go to this location and 6 you will find server.xml. Use that server.xml and it will work.

My 5 actual tomcat directory is:

C:\apache-tomcat-7.0.62x64\apache-tomcat-7.0.62\conf

and my Eclipse 4 Tomcat server uses:

C:\workspace\JSF\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf 

Use the workspace path 3 and server.xml from this location.

Add this in server.xml inside 2 the host tag:

< Context docBase="D:/personal"  path="/images" />

and it will work if D:/personal has 1.png, and 1 then the url http://localhost:8080/images/1.png will load the image.

More Related questions