英文:
How to pass VM Options in Maven
问题
<properties>
<vertx.disableFileCPResolving>true</vertx.disableFileCPResolving>
<log4j.configurationFile>log4j2.xml</log4j.configurationFile>
<vertx.logger-delegate-factory-class-name>io.vertx.core.logging.Log4j2LogDelegateFactory</vertx.logger-delegate-factory-class-name>
<APP_ID>9757632</APP_ID>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-Dvertx.disableFileCPResolving=true</arg>
<arg>-Dlog4j.configurationFile=log4j2.xml</arg>
<arg>-Dlogger-factory-class-name=io.vertx.core.logging.Log4j2LogDelegateFactory</arg>
<arg>-DAPP_ID=9757632</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
请注意,以上内容是您所提供的信息的翻译。如果您有任何问题或需要进一步的帮助,请随时提问。
英文:
I need the following vm options to be passed into maven.
-Dvertx.disableFileCPResolving=true
-Dlog4j.configurationFile=log4j2.xml
-Dlogger-factory-class-name=io.vertx.core.logging.Log4j2LogDelegateFactory
-DAPP_ID=9757632
At present I am passing them via the IDE (Intellij) and everything is working fine. (See screenshot)
But how can I add them as part of the Maven project, possibly via POM file or a resource file?
Tried the following in my POM file based on the suggestion in this page but it doesn't work.
https://stackoverflow.com/a/39751176/9401029
<properties>
<vertx.disableFileCPResolving>true</vertx.disableFileCPResolving>
<log4j.configurationFile>log4j2.xml </log4j.configurationFile>
<vertx.logger-delegate-factory-class-name>io.vertx.core.logging.Log4j2LogDelegateFactory</vertx.logger-delegate-factory-class-name>
<APP_ID>9757632</APP_ID>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>${vertx.disableFileCPResolving}</arg>
<arg>${log4j.configurationFile}</arg>
<arg>${vertx.logger-delegate-factory-class-name}</arg>
<arg>${APP_ID}</arg>
</compilerArgs>
</configuration>
</plugin>
Saw another example using the file JVMARGS (no extension) which holds following values.
-Dvertx.disableFileCPResolving=true
-Dlog4j.configurationFile=log4j2.xml
-Dlogger-factory-class-name=io.vertx.core.logging.Log4j2LogDelegateFactory
-DAPP_ID=9757632
Placed this file at the root level and within resource folder. That doesn't work either.
Please advice how to pass these values into my maven project, preferably via POM file. Thank you.
答案1
得分: 2
Maven有无数种运行Java代码的方式,通过各种插件实现 -- 而且它们并不都使用相同的方法将JVM命令行开关传递给正在运行的程序。
例如,exec
插件 1 会 respest 环境变量 MAVEN_OPTS
。这是一个 系统 环境变量,不是Java环境变量。
因此,在Linux上,要在Maven下使用特定的 -Xmx
设置运行程序,我可能会这样做
$ MAVEN_OPTS="-Xmx2000m" mvn exec:java
但请注意,您需要根据您的平台以适当的方式设置 MAVEN_OPTS
。对于Windows上的IDE,您可能需要使用控制面板来进行设置。或者您的IDE在运行Maven时可能会提供设置环境变量的方法 -- 这取决于IDE。
因此,简短的答案是,我猜您需要准确地找到您在Maven中使用的执行插件,然后查看该插件的文档,以了解如何配置它以使用适当的JVM设置。
不过,最终您可能不会长期在Maven下运行应用程序。您需要找到一种方法来独立于Maven指定JVM设置 -- 例如在脚本或批处理文件中。
1 https://www.mojohaus.org/exec-maven-plugin/usage.html
英文:
Maven has a gazillion ways to run Java code, through various plug-ins -- and they don't all use the same methods to pass JVM command-line switches to the running program.
For example, the exec
plugin 1 respects the environment variable MAVEN_OPTS
. This is a system environment variable, not a Java environment variable.
So on Linux, to run a program under Maven with a specific -Xmx
setting I might do
$ MAVEN_OPTS="-Xmx2000m" mvn exec:java
But note that you'd need to set MAVEN_OPTS
in a way that is appropriate for your platform. For an IDE on Windows, you might need to use the Control Panel to do this. Or your IDE might provide a way to set the environment variable when it runs Maven -- that depends on the IDE.
So the short answer, I guess, is that you need to find exactly which execution plug-in you're using in Maven, and look at the documentation for that plug-in to see how to configure it to use the appropriate JVM settings.
In the end, though, you're probably not going to be running your application under Maven in the long term. You'll need to find a way to specific JVM settings independently of Maven -- in a script, or batch file, for example.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论