How to configure Tomcat to serve image files from custom folder or NFS Share.

You can use to Tomcat to serve images, PDF, xls, docx from the custom directory. In our case, we used centralized NFS share to serve images to our custom Apex Applications.

Here is the how

Add a <context> to the tomcat/conf/server.xml file.

Windows example:
<Context docBase=”c:\Documents and Settings\The User\images” path=”/images” />

Linux example:
<Context docBase=”/var/project/images” path=”/images” />

Example of Server.xml (trimmed):

<Server port=”8025″ shutdown=”SHUTDOWN”>

<Service name=”Catalina”>

<Engine name=”Catalina” defaultHost=”localhost”>

<Host appBase=”webapps”
autoDeploy=”false” name=”localhost” unpackWARs=”true”
xmlNamespaceAware=”false” xmlValidation=”false”>

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

<!–Custom Images Directory–>
<Context docBase=”/nfsshare/custom/images” path=”/images” />

</Host>
</Engine>
</Service>
</Server>

Now, you should be able to pull filesĀ (e.g. /nfsshare/custom/images/TestImage.jpg) asĀ http://localhost:8080/custom/images/TestImage.jpg

test

Advertisement