Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Add-Opens in Java Jar MANIFEST

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

like image 601
Enrico Olivelli Avatar asked May 15 '19 13:05

Enrico Olivelli


2 Answers

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

Emphasis mine

like image 127
A248 Avatar answered Sep 18 '22 14:09

A248


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
like image 20
Abdelrahman Elattar Avatar answered Sep 17 '22 14:09

Abdelrahman Elattar