开发者

Setting Runtime Property in Web Application

开发者 https://www.devze.com 2023-02-15 00:34 出处:网络
I am planning to use JGroups开发者_开发百科 in a web application. JGroups by default uses IPv6 for multicasting of messages.JGroups can only be configured to use IPv4 by setting a property like the f

I am planning to use JGroups开发者_开发百科 in a web application.

JGroups by default uses IPv6 for multicasting of messages. JGroups can only be configured to use IPv4 by setting a property like the following (see docs)

-Djava.net.preferIPv4Stack=true

This does not work if set in code. What are my options when running a war file in an application server for setting this property, specifically tomcat and glassfish?


It seems to me the following route might work. First, add a ServletContextListener to your web app and register it in web.xml before JGroups is loaded.

Now, inside the contextInitialized method, use System.setProperty("java.net.preferIPv4Stack", "true").

Disclaimer: not tested.


Unless you have a specific reason to put this in code, it can easily be configured for Tomcat by setting the environment variable CATALINA_OPTS (to -Djava.net.preferIPv4Stack=true). I think the proper place to do this is to create ${CATALINA_HOME}/bin/setenv.sh and place the setting in there.

0

精彩评论

暂无评论...
验证码 换一张
取 消