wood burning stoves 2.0*
The moose likes Web Services and the fly likes Place .ini conf file inside the war package. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Place .ini conf file inside the war package." Watch "Place .ini conf file inside the war package." New topic
Author

Place .ini conf file inside the war package.

Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
Hello,

I have a quick question considering my rest webservice. I would like to place an .ini file with configuration parameters inside an war file, so that I can change them wile the app is deployed on tomcat without recompiling. Can any give an advice on how to do this? And how to open this file (what path) in my java code. I am using maven so an advice on how to write a special script in the pom.xml file would be great.

Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Adam,
You can do it in many ways!

1. Context parameters in web.xml, if you are expecting parameters to be used by whole of your web application.


2. Servlet parameters in web.xml, if you are expecting parameters to be used only by certain Servlets (web services and related ones)


3. You can use Java Properties file loader class by declaring all your configurable parameters in a .properties file. This can be loaded at the start of your web application or whenever you try to access one of the properties.
E.g. Check out this link


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
Naren Chivukula - Thank you for the response, however I don't think you understood me well. Because all of the given options can only be change on compilation (as far as I understand - correct me if I'm wrong). What I need is a file with properties (I think .ini files are used for that usually) that would be included in my web app when it is deployed on tomcat. So that when I want to change sth. (for example address of a server to connect with) I can do this while the app is deployed on tomcat, without a need to recompile the whole project and redeploy the war file again. I think none of the options you have given me, allows this kind of functionality (or, again, correct if I'm wrong).
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Adam,
Because all of the given options can only be change on compilation (as far as I understand - correct me if I'm wrong)

They don't need to recompile your java classes. Options 1 and 2 require you to just restart your server unless your server supports hot deployment. Option 3 can be used without even restarting server if you change any of your properties on the fly.
I think none of the options you have given me, allows this kind of functionality (or, again, correct if I'm wrong).

All the three options I provided would work as per your requirement if you had a close study.
(I paraphrase your requirement is not to rebuild and redeploy your whole project for any changes you would like to make)
Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
Ok I will look closer at this, though I though all of them would require recompiling the project :> Thanks for the advice :>
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Perhaps not exactly what you are looking for, but here goes:
If you use Spring and do not mind writing a little Groovy, then you can write a Groovy script that may be altered at runtime. You tell the Spring DI container at which interval it is to examine the script file for changes like in the following example:

If The Spring DI container notices any differences in the bean, it is recompiled and the implementation running in your application is updated, without the need for the program to be recompiled or even restarted.
Let me know if you want more information on the above!
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
 
jQuery in Action, 2nd edition
 
subject: Place .ini conf file inside the war package.
 
Similar Threads
Regarding .ini files in JSP
including ini file in project
How to reload an ini file without restarting weblogic 7.0 ??
Burning multiple linux ISO images to DVD
how to read .ini file from java code