Multiple Add-Opens in Java Jar MANIFEST
Asked Answered
C

3

12

I have an executable Jar which is using reflection in order to access some java internal (actually I am shading some third party library like Netty, DNSJava...)

I see that adding this entry to the MANIFEST of the Jar

Add-Opens: java.base/sun.net.dns

solves my first problem:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.xbill.DNS.ResolverConfig (file:/home/diennea.lan/enrico.olivelli/dev/magnews/magnews.installer/target/magnews-24.05-SNAPSHOT.dev-b199bacf8f2-noci-installer.jar) to method sun.net.dns.ResolverConfiguration.open()
WARNING: Please consider reporting this to the maintainers of org.xbill.DNS.ResolverConfig
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

But now I have a second warning:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.postgresql.jdbc.TimestampUtils (file:/home/diennea.lan/enrico.olivelli/dev/magnews/magnews.installer/target/example/.tmpPackage/packages/postgresql.jar) to field java.util.TimeZone.defaultTimeZone
WARNING: Please consider reporting this to the maintainers of org.postgresql.jdbc.TimestampUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

And I need to add this new exception

Add-Opens: java.base/java.util

I am trying with:

Add-Opens: java.base/java.util,java.base/sun.net.dns
Add-Opens: java.base/java.util;java.base/sun.net.dns
Add-Opens: java.base/java.util:java.base/sun.net.dns

Without results. I can't find any "specification" about Add-Opens

Chiropody answered 15/5, 2019 at 13:34 Comment(1)
Separate them with spaces, as described in openjdk.java.net/jeps/261. (Why the !#$& does the postgresql driver need to access a private field of TimeZone, especially something accessible via a public method?)Bentinck
T
12

JEP 261: Module System explains how to specify multiple module/package combinations:

Two new JDK-specific JAR-file manifest attributes are defined to correspond to the --add-exports and --add-opens command-line options:

Add-Exports: <module>/<package>( <module>/<package>)*

Add-Opens: <module>/<package>( <module>/<package>)*

The value of each attribute is a space-separated list of slash-separated module-name/package-name pairs

For example,

Add-Opens: java.base/java.util java.base/sun.net.dns
Topeka answered 21/3, 2021 at 20:58 Comment(1)
An example would be very helpfulLaboy
O
9

You can add multiple add-opens during running application.

Example could help:

java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED -jar test.war
Outgo answered 7/7, 2021 at 12:26 Comment(0)
S
4

What worked for me

  1. Add-opens at the start of file - i.e. it is the first attribute in manifest
  2. one space at the end, one at start - for each line.
  3. only one entity on each line.

enter image description here

Skipjack answered 21/10, 2022 at 0:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.