Maven组件插件-多版本:true [英] Maven Assembly Plugin - Multi-Release:true

查看:116
本文介绍了Maven组件插件-多版本:true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My multi-jar app runs in Java 11 and shows a warning related to Log4j2:

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

WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.

它不会崩溃,但是因为操作团队(AppDynamics监视器)已经问过我了,所以我很烦.我读到我需要在清单中使用"Multi-Release:true"条目,但我不知道如何告诉Maven Assembly Plugin添加它.

It doesn't crash, but quite bothers me since the Operations team (AppDynamics monitor) has asked me about it. I read that I need to use the "Multi-Release:true" entry in the manifest, but I don't kow how to tell the Maven Assembly Plugin to add it.

我在pom.xml中不使用任何其他插件.我应该改用 Maven Shade插件吗?

I don't use any other plugin in the pom.xml. Should I use the Maven Shade Plugin instead?

无论如何,这是我pom.xml的Maven组件插件部分.

Anyway, here's the Maven Assembly Plugin section of my pom.xml.

<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>

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

The library I'm including (that I also wrote) uses Log4j 2 as a dependency, as shown below:

<!-- 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>

如何消除此警告?

推荐答案

您需要在jar的MANIFEST.MF中将Multi-Release设置为true.在Assembly插件中,您应该可以通过添加

You need to set Multi-Release to true in the jar's MANIFEST.MF. In the assembly plugin you should be able to do that by adding

      <archive>
        <manifestEntries>
          <Multi-Release>true</Multi-Release>
        </manifestEntries>
      </archive>

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

to the configuration section of your assembly configuration.

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

You could also use the jar plugin to create your jar. For that you would do

<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>

这篇关于Maven组件插件-多版本:true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆