简体   繁体   English

在log4j.properties文件中设置jvmargs

[英]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. 这有点奇怪的请求,但是我试图在log4j.properties文件中设置一些jvmargs。 At present I use ant to for example set some args.... 目前,我使用ant来设置一些参数。

jvmarg value="-Dmail.smtp.socketFactory.port=465" 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. ...但是最好将其中一些与日志记录相关的参数分组到.properties文件中。 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... 如果您的示例来自您的实际情况,则可以通过编程方式为Java邮件设置此值...

The SMTP protocol provider supports the following properties, which may be set in the JavaMail Session object. SMTP协议提供程序支持以下属性,可以在JavaMail Session对象中设置这些属性。 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 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. 上面的示例也适用于mail.smtp.socketFactory.port。

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: 如果可以在JVM启动之后添加属性,则可以将属性添加到属性文件,该文件列出要添加到SystemProperties集合的所有属性,例如:

# 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. 您的启动代码可以读取systemprops值,在空格上分割,然后将结果的属性列表添加到SystemProperties集合中,同时从属性集合中读取值。

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. 这样,您的代码无需知道要添加到系统属性的属性,仅需知道要添加的属性是由systemprops属性定义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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