How to pass System Properties in web.xml

In Java standalone application, you can use -D option to pass in the system properties :


$ java -Dgeoip.file="/home/mkyong/geoip/test.db" test.jar

In Java web application, you can pass the system properties via context-param in web.xml :

web.xml

<web-app>
	<context-param>
	    <param-name>geoip.file</param-name>
	    <param-value>/home/mkyong/geoip/test.db</param-value>
	</context-param>
</web-app>

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
luis
8 years ago

hi, is there anyway to use -Dgeoip.file jvm parameter inside web.xml? I mean something like:
$ java -Dgeoip.file=”/home/mkyong/geoip” test.jar

geoip.file
${geoip.file}/test.db

this example is not running ok.

ramireddy vakamalla
10 years ago

i all ways love reading mkyong.com examples . thank u yong garu ,i never for got u ,u are very great man.

i said to my friends if u have any doughts sees mkyong.com.

please keep good examples and enhancement real time senarios.

and also keep WebService programs each and every topic.
like java web based ,interacting with database and using web service to communicate with other java web app having strong stuff.

isosceles triangle
10 years ago

Great, thanks, very succinct