Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass an argument while deploying a WAR file?

Tags:

java

war

I basically need to pass an argument to the WAR file that contains the path to my config.json.

I want to achieve it in such a way so that once the project has been exported as a WAR file, I should be able to change the argument without opening the WAR file and having to export it again.

I understand I can pass arguments in the web.xml which can be obtained in the servlet but wouldn't changing the web.xml require me to open the WAR file?

I am using jetty-runner.jar to deploy my webapp.

like image 272
Anirudh Avatar asked Mar 19 '23 03:03

Anirudh


2 Answers

When you run jetty-runner.jar, you may pass a proprty to jvm like this java -jar jetty-runner.jar my.war -Dproperty.name=value

In your web.xml you may use following syntax

<context-param>
    <param-name>property.name</param-name>
    <param-value>${property.name}</param-value>
</context-param>

See an example here: http://www.xinotes.net/notes/note/1611/

like image 97
white Avatar answered Mar 31 '23 20:03

white


I can see 2 solution to you problem:
1) You define an environment variable that specifies the path to your config.json on the server that hosts you jetty instance
2) You add to the class path the folder that contains the config.json and access it from your web application.

like image 30
calbar Avatar answered Mar 31 '23 20:03

calbar