@@ -29,6 +29,9 @@ <h1>Java Native Access (JNA)</h1>
29
29
< h2 > Table of Contents</ h2 >
30
30
< ul >
31
31
< li > < a href ="#loading "> Loading JNA</ a >
32
+ < ul >
33
+ < li > < a href ="#loading-jdk24 "> Special considerations for JDK24+</ a >
34
+ </ ul >
32
35
< li > < a href ="#library-mapping "> Library Mapping</ a >
33
36
< li > < a href ="#function-mapping "> Function Mapping</ a >
34
37
< li > < a href ="#marshalling "> Type Mapping</ a >
@@ -81,6 +84,53 @@ <h2>Loading JNA</h2>
81
84
library (e.g. for different architectures) in the same directory.
82
85
< p />
83
86
87
+ < a href =#navbar_top > Top</ a >
88
+ < a name ="loading-jdk24 "> </ a >
89
+ < h3 > Special considerations for JDK24+</ h3 >
90
+ The JDK moves to "safe by default" or "Integrity by Default" settings. Settings
91
+ that might compromise the integrity provided by the JVM are off by default.
92
+ Since JDK 24 this also affects the usage of Java Native Interface (JNI). This
93
+ is part of the foundation JNA is built upon. For JDK 24 this is a warning, in
94
+ the future JNI will be restricted to explicitly enabled modules.
95
+ < p />
96
+ To fix the warnings and prepare for the future, the applications using JNA need
97
+ to be modified. The java launcher will need to be instructed to allow JNI for
98
+ the module JNA was loaded from. In the most basic case JNA is loaded from the
99
+ classpath. For example, the built in mini-check of JNA can be invoked as:
100
+
101
+ < blockquote > < code > < pre >
102
+ java -jar jna.jar
103
+ </ blockquote > </ code > </ pre >
104
+
105
+ This will need to be modified to:
106
+
107
+ < blockquote > < code > < pre >
108
+ java --enable-native-access=ALL-UNNAMED -jar jna.jar
109
+ </ blockquote > </ code > </ pre >
110
+
111
+ If JNA is loaded from the modulepath
112
+
113
+ < blockquote > < code > < pre >
114
+ java -p jna-jpms.jar -m com.sun.jna
115
+ </ blockquote > </ code > </ pre >
116
+
117
+ That will need to be modified to:
118
+
119
+ < blockquote > < code > < pre >
120
+ java --enable-native-access=com.sun.jna -p jna-jpms.jar -m com.sun.jna
121
+ </ blockquote > </ code > </ pre >
122
+
123
+ For executable JARs the manifest attribute < code > Enable-Native-Access</ code > can
124
+ be set to the value < code > ALL-UNNAMED</ code > to enable native access for this
125
+ case.
126
+ < p />
127
+ How these changes are applied to the concrete project is highly dependending on
128
+ the setup of that project and thus no general advise can be presented here.
129
+ < p />
130
+ More information can be found on the page describing < a
131
+ href ="https://openjdk.org/jeps/472 " target ="_blank "> JEP 472: Prepare to Restrict
132
+ the Use of JNI</ a >
133
+ < p />
84
134
< a href =#navbar_top > Top</ a >
85
135
< a name ="library-mapping "> </ a >
86
136
< h2 > Library Mapping</ h2 >
0 commit comments