Skip to content

Commit 45c4476

Browse files
Merge pull request #1669 from matthiasblaesing/document-jdk24
Document changes required for running JNA on JDK24+
2 parents 3a8677e + f56b395 commit 45c4476

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

build.xml

+2
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ osname=macosx;processor=aarch64
424424
<attribute name="Multi-Release" value="true"/>
425425
</manifest>
426426
<manifest file="@{target}" mode="update" unless:true="@{module-info}">
427+
<attribute name="ModuleMainClass" value="com.sun.jna.Native"/>
427428
<attribute name="Automatic-Module-Name" value="com.sun.jna"/>
428429
</manifest>
429430
</sequential>
@@ -433,6 +434,7 @@ osname=macosx;processor=aarch64
433434
<build-manifest target="${build}/manifest/module.mf" module-info="true"/>
434435
<build-manifest target="${build}/manifest/automatic.mf" module-info="false"/>
435436
<ModuleGenerator
437+
mainClass="com.sun.jna.Native"
436438
targetFile="${build}/manifest/module-info.class"
437439
name="com.sun.jna"
438440
version="${jna.major}.${jna.minor}.${jna.revision}"

src/com/sun/jna/overview.html

+50
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ <h1>Java Native Access (JNA)</h1>
2929
<h2>Table of Contents</h2>
3030
<ul>
3131
<li><a href="#loading">Loading JNA</a>
32+
<ul>
33+
<li><a href="#loading-jdk24">Special considerations for JDK24+</a>
34+
</ul>
3235
<li><a href="#library-mapping">Library Mapping</a>
3336
<li><a href="#function-mapping">Function Mapping</a>
3437
<li><a href="#marshalling">Type Mapping</a>
@@ -81,6 +84,53 @@ <h2>Loading JNA</h2>
8184
library (e.g. for different architectures) in the same directory.
8285
<p/>
8386

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/>
84134
<a href=#navbar_top>Top</a>
85135
<a name="library-mapping"></a>
86136
<h2>Library Mapping</h2>

0 commit comments

Comments
 (0)