简体   繁体   English

如何在 Maven 中传递 VM 选项

[英]How to pass VM Options in Maven

I need the following vm options to be passed into maven.我需要将以下 vm 选项传递给 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.目前我正在通过 IDE (Intellij) 传递它们,并且一切正常。 (See screenshot) (见截图)

虚拟机选项

But how can I add them as part of the Maven project, possibly via POM file or a resource file?但是如何将它们添加为 Maven 项目的一部分,可能是通过 POM 文件或资源文件?

Tried the following in my POM file based on the suggestion in this page but it doesn't work.根据此页面中的建议,在我的 POM 文件中尝试了以下操作,但不起作用。

https://stackoverflow.com/a/39751176/9401029 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.看到另一个使用文件 JVMARGS(无扩展名)的示例,其中包含以下值。

-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.请建议如何将这些值传递到我的 maven 项目中,最好是通过 POM 文件。 Thank you.谢谢你。

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. Maven 有无数种方式来运行 Java 代码,通过各种插件——它们并不都使用相同的方法将 JVM 命令行开关传递给正在运行的程序。

For example, the exec plugin [1] respects the environment variable MAVEN_OPTS .例如, exec插件 [1] 尊重环境变量MAVEN_OPTS This is a system environment variable, not a Java environment variable.这是一个系统环境变量,而不是 Java 环境变量。

So on Linux, to run a program under Maven with a specific -Xmx setting I might do因此,在 Linux 上,要在 Maven 下使用特定的-Xmx设置运行程序,我可能会这样做

$ 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.但请注意,您需要以适合您平台的方式设置MAVEN_OPTS For an IDE on Windows, you might need to use the Control Panel to do this.对于 Windows 上的 IDE,您可能需要使用控制面板来执行此操作。 Or your IDE might provide a way to set the environment variable when it runs Maven -- that depends on the IDE.或者您的 IDE 可能会提供一种在运行 Maven 时设置环境变量的方法——这取决于 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.因此,我想简短的回答是,您需要准确地找到您在 Maven 中使用的执行插件,并查看该插件的文档以了解如何配置它以使用适当的 JVM 设置。

In the end, though, you're probably not going to be running your application under Maven in the long term.但最终,从长远来看,您可能不会在 Maven 下运行您的应用程序。 You'll need to find a way to specific JVM settings independently of Maven -- in a script, or batch file, for example.您需要找到一种独立于 Maven 的特定 JVM 设置的方法——例如,在脚本或批处理文件中。

[1] https://www.mojohaus.org/exec-maven-plugin/usage.html [1] https://www.mojohaus.org/exec-maven-plugin/usage.html

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

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