I have a application which is bundled and gets deployed as a WAR file only.
There is a property file xs.properties which I use to store my login username and password in encrypted format.
I have a passreset servlet which resets the password by encrypting & checking the old password and username and if both matches then it writes the new password and username in encrypted format to the property file xs.properties.
My trouble is how can I replace the xs.properties file with the new one. I dont know how I will be able to give a relative path which will replace the xs.properties file with the new one.
Now its creating the new xs.properties file at "webapps"(Tomcat) instead of ABC/WEB-INF/classes folder.
Can somebody let me know what shall be mine approach to make it store the new file @ ABC/WEB-INF/classes folder.
Below code creates the file @ webapps in Tomcat. In webapps folder my war file is deployed.
LAYOUT OF My WAR
I should point out that changing files within the web app is not a great idea. It makes updating and redeployment a nightmare. I'd investigate storing the properties file outside the web app, perhaps identifying its location as a context variable.
After taking your suggestion i tried to get the xs.properties file path from environment.
I made a class property and added all the custom names like below:
And I call it like below:
I start my tomcat by giving JAVA_OPTS as in VM options
But I get a null pointer exception when ever i try to access the property file.
Am I missing something or I shall do it in some other way.
In any case, getBundle() loads properties from the classpath, which in this case you are not using.
You might want to check out the Properties object.
Also, why use an environment variable rather than a context variable?
Depending on how your app is deployed, there may or may not be a path to the properties file in your system.
The getRealPath method takes a String argument and returns a String
representation of a file on the local file system to which a path corresponds. The
getPathTranslated method computes the real path of the pathInfo of the request.
In situations where the servlet container cannot determine a valid file path for
these methods, such as when the Web application is executed from an archive, on
a remote file system not accessible locally, or in a database, these methods must