3

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

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

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.

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

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>

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>

How can I get rid of this warning?

Naman
  • 27,789
  • 26
  • 218
  • 353
Joe DiNottra
  • 836
  • 8
  • 26
  • 1
    You can add the configuration for the maven-assembly-plugin with the following: https://maven.apache.org/shared/maven-archiver/index.html https://maven.apache.org/plugins/maven-assembly-plugin/usage.html – khmarbaise Mar 18 '20 at 14:19

2 Answers2

11

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.

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>
rgoers
  • 8,696
  • 1
  • 22
  • 24
0

You can use maven-assembly-plugin for this as follows:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <executions>
    <execution>
      ...
      <configuration>
        <archive>
          ...
          <manifestEntries>
            <Multi-Release>true</Multi-Release>
          </manifestEntries>
        </archive>
        ...
      </configuration>
    </execution>
  </executions>
</plugin>
acm
  • 2,086
  • 3
  • 16
  • 34