Deploying a war file using shared resources

Consider the following example structure

- Project
    - www
        - files
            + documents
            + html
            + images
            + scripts
    - WEB-INF
        * web.xml

      

The documents folder should be a symbolic link or some other way external from the war file as users will add and remove documents (via a mapped network drive).

I would like to deploy a webapp as a war file, but I don't know how to do this, and please consider this. Could you please provide some pointers? /Adam

0


source to share


9 replies


If it's static content, you might be better off submitting to the app server using the web server and hosting the static content there. You free the application server from serving static data and saving the network route for loading.



+1


source


I agree with @ duffymo.myopenid.com that in your application server with a webserver that serves static content for certain url prefixes is a good, clean solution.



If this is not possible in your environment, or if you decide you want to handle it in the web application itself, you can write a servlet that will actually do the same. For example, create a servlet that maps to the / documents / * URL pattern. This servlet can parse the URL (/documents/some/file.png) to determine the relative filename (some / file.png). It could then read and return the corresponding content in the external directory (/staticDocs/some/file.png).

+1


source


Why not save documents, etc. in the database and then use a web app to access the database and allow users to upload files that way? Does it have to be a mapped network drive?

Otherwise, if you know which is, you can always build the jnlp file dynamically and pass filelists, etc. as arguments (if they are server-side).

Let's say we need to know a little more about what you are trying to accomplish.

0


source


Basically, it is a webapp that combines information from different sources and generates documents. It is a requirement that users be able to create and upload documents manually from the web without logging into the web application.

Putting the path of the document location as a context variable is definitely doable. I think this is the easiest way. / Adam

0


source


Unfortunately for you .war files are .zip files and .zip files do not support symbolic links. If you are ONLY deploying to a Windows machine, you might be lucky to use a shortcut file. However, I'm not sure if the server app will like it (maybe not).

I would recommend adding a configuration parameter to your application that allows you to specify the full path to the document folder. The default path must be relative ("./www/files/documents") for the application to work out of the box without additional configuration.

0


source


Many Java web servers support "exploded war files" where you simply unzip your .war file into your deployment directory. With tomcat, you copy this to $CATALINA_HOME/webapps

and you're done.

This should work for you.

0


source


How about creating an environment variable on your server that points to the directory where the files are stored? An environment variable might work better than the setting in your WAR file, as you can deploy your application to a new environment (possibly by going from DEV to PROD) without changing your WAR file.

From your java code, you can reference this environment setting: String docPath = System.getProperty ("DOC_PATH");

0


source


In Apache Tomcat, it may sometimes need to be reused via tomcat RewriteValve like this:

META-INF / context.xml:

<Context>
  <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
</Context>

      

WEB-INF / rewrite.config:

RewriteRule (.*)/login(/.*\.)(png|jpg|js|css) $1$2$3 

      

Now the path /appContext/login/

will use the same images / js / css as/appContext/

Of course, as with all regex solutions for ANY problem, keeping the complexity of an expression low is important for performance.

0


source


Sounds like you need a Web Content Management System ( CMS ).

-1


source







All Articles