• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Place .ini conf file inside the war package.

 
Adam Kronicki
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 577
Java Notepad Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adam Kronicki
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 577
Java Notepad Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic