简体   繁体   中英

Setting jvmargs in log4j.properties file

This is a bit of a weird request but I am trying to set some jvmargs in the log4j.properties file. At present I use ant to for example set some args....

jvmarg value="-Dmail.smtp.socketFactory.port=465"

... but it would be great to group a few of these logging relevant arguments into the .properties file. Does anyone know how to do this?

Thanks in advance!

Log4j仅在JVM启动后才读取属性文件-这意味着它不会影响JVM参数。

If your example is from your actual situation then you can set this value programatically for the java mail...

The SMTP protocol provider supports the following properties, which may be set in the JavaMail Session object. The properties are always set as strings; the Type column describes how the string is interpreted. For example, use

  props.put("mail.smtp.port", "888"); 

http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html

This example above should work for mail.smtp.socketFactory.port also.

If the properties can be added after JVM startup, you could add a property to your properties file that lists all properties that you want to add to the SystemProperties collection, something like:

# property names of system properties
systemprops=mail.smtp.port mail.smtp.socketFactory.class

mail.smtp.port=465
mail.smtp.socketFactory.class=some.class

Your startup code can read the systemprops value, split on whitespace and add the resulting list of properties to the SystemProperties collection while reading the values from your properties collection.

This way your code does not need to know which properties to add to system props, only that the properties to add are defined by the systemprops property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM