Reputation: 9311
I need to access some files on servers from servlet. They have different paths on my development machine and on the deployment server. I would like to put some config file (with paths) somewhere (like shared
dir in capistrano deployment) so application could read it. Or maybe set some property on the application server or anything like that. I can use Tomcat, Jetty or Glassfish.
Currently I made a config file in WEB-INF with config for local machine. Deployment script that copies .war on the server, modifies the war file by putting server config file inside. It works, but is not too nice, and if something changes with paths on the server I would have to change local file and redeploy application.
Can you suggest better solution?
Upvotes: 1
Views: 1691
Reputation: 3549
I agree with kgiannakakis, but there are some limitations to that as well
- Storing properties/xml configurations
in database is definately an option
but not always feasible specially if it is an non property resource like XML.
- JNDI look up's are performance hit
and you can't store xml's there as well
- If you have multiple copies of
application deployed on same server,
environment variables can't be used.
- All of above cannot be used to do
something like
MyClass.getResourceAsStream()
.
If above solution is ok then fine else you can use the concept of shared libraries. I am not sure of how it works with above app servers you mentioned but given below are links for Geronimo, WASCE, IBM Websphere. Concept is that during deployment you specify additional classpath for your EAR.
WASCE 2.1.0 http://publib.boulder.ibm.com/wasce/V2.1.0/en/shared-library.html
Upvotes: 1
Reputation: 104168
There are a couple of similar questions here in SO. This is one I've found, I remember there are more.
Anyway, this link from the above answer could be helpful.
A summary of your options are:
Upvotes: 2
Reputation: 16311
The usual way to do this is to configure your dependencies inside the servlet container, and expose them via JNDI. In your case, just exposing a String with the path would probably be sufficient.
The JNDI tutorial and Tomcat's JNDI docs should help you get started. JNDI also nicely integrates with Spring, in case you use the Spring IOC container.
Upvotes: 1