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
source to share
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).
source to share
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.
source to share
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
source to share
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.
source to share
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");
source to share
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.
source to share