Main Tutorials

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>

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
luis
6 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
8 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
8 years ago

Great, thanks, very succinct