Anirudh
Anirudh

Reputation: 55

How to pass an argument while deploying a WAR file?

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.

Upvotes: 4

Views: 7017

Answers (2)

calbar
calbar

Reputation: 26

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.

Upvotes: 1

white
white

Reputation: 1913

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/

Upvotes: 6

Related Questions