如何从Maven命令传递log4j2.configurationFile环境变量

huangapple go评论62阅读模式
英文:

How to pass log4j2.configurationFile env variable from maven command

问题

我想在我的Spring Boot应用程序之外使用一个放置在log4j2.xml文件。

当我使用以下命令通过java命令运行时,它能正常工作。

java -Dlog4j2.configurationFile=file:/Users/ilam/Documents/abc.xml -jar target/myapp.war

但是当我运行以下命令时

mvn -Dlog4j2.configurationFile=file:/Users/ilam/Documents/abc.xml clean spring-boot:run

我的abc.xml文件没有被使用。

传递-Dspring-boot.run.arguments也没有帮助,因为看起来log4j会在spring boot之前启动。

  1. 我不想使用spring配置文件。
  2. 我不想修改pom.xml文件。基本上我不想在应用程序代码中做任何更改。
英文:

I want to use a log4j2.xml placed outside my spring-boot app.

when i run using java command with below command it works fine.

java -Dlog4j2.configurationFile=file:/Users/ilam/Documents/abc.xml -jar target/myapp.war

but when i run

mvn -Dlog4j2.configurationFile=file:/Users/ilam/Documents/abc.xml clean spring-boot:run

my abc.xml is not used.

passing -Dspring-boot.run.arguments did not help either because it looks like log4j kicks in before spring boot kicks in

  1. I don't want to use spring profiles
  2. I don't want to touch pom.xml. Basically i don't want touch anything in application code.

答案1

得分: 1

-Dspring-boot.run.arguments 是用于程序参数的。

您应该使用 spring-boot.run.jvmArguments

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dlog4j2.configurationFile=file:/Users/ilam/Documents/abc.xml"
英文:

-Dspring-boot.run.arguments is for program arguments.

You should be using spring-boot.run.jvmArguments.

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dlog4j2.configurationFile=file:/Users/ilam/Documents/abc.xml"

huangapple
  • 本文由 发表于 2020年9月26日 03:36:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/64070376.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定