Maven 程序集插件 - 多版本:true

Joe*_*tra 3 java maven log4j2 java-11

我的多 jar 应用程序在 Java 11 中运行并显示与 Log4j2 相关的警告:

警告:不支持 sun.reflect.Reflection.getCallerClass。这会影响性能。

它没有崩溃,但很困扰我,因为运营团队(AppDynamics 监视器)向我询问了它。我读到我需要在清单中使用“Multi-Release:true”条目,但我不知道如何告诉 Maven Assembly Plugin 添加它。

我没有在 pom.xml 中使用任何其他插件。我应该使用Maven Shade Plugin吗?

无论如何,这是我的 pom.xml 的 Maven Assembly Plugin 部分。

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>3.2.0</version>
  <configuration>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
  <executions>
    <execution>
      <id>make-assembly</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我包含的库(我也写过)使用 Log4j 2 作为依赖项,如下所示:

<!-- Log4j 2 -->

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>2.12.1</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-core</artifactId>
  <version>2.12.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我怎样才能摆脱这个警告?

rgo*_*ers 8

您需要在 jar 的 MANIFEST.MF 中将 Multi-Release 设置为 true。在程序集插件中,您应该能够通过添加来做到这一点

      <archive>
        <manifestEntries>
          <Multi-Release>true</Multi-Release>
        </manifestEntries>
      </archive>
Run Code Online (Sandbox Code Playgroud)

到程序集配置的配置部分。

您还可以使用 jar 插件来创建您的 jar。为此你会做

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
        <manifestEntries>
            <Multi-Release>true</Multi-Release>
        </manifestEntries>
    </archive>
    <finalName>mr-jar-demo.jar</finalName>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)