Skip to content

Commit 4af936e

Browse files
maschnetworkTingDaoK
authored andcommitted
Example for registration via feature
1 parent cae4b5e commit 4af936e

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@
326326
</profiles>
327327

328328
<dependencies>
329+
329330
<dependency>
330331
<groupId>junit</groupId>
331332
<artifactId>junit</artifactId>
@@ -351,6 +352,11 @@
351352
<version>1.4</version>
352353
<scope>test</scope>
353354
</dependency>
355+
<dependency>
356+
<groupId>org.graalvm.sdk</groupId>
357+
<artifactId>graal-sdk</artifactId>
358+
<version>23.1.1</version>
359+
</dependency>
354360
</dependencies>
355361
<build>
356362
<resources>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package software.amazon.awssdk.crt.graalvm;
2+
3+
4+
import org.graalvm.nativeimage.hosted.Feature;
5+
import org.graalvm.nativeimage.hosted.RuntimeJNIAccess;
6+
import software.amazon.awssdk.crt.http.HttpRequestBase;
7+
8+
9+
class JNIRegistrationFeature implements Feature {
10+
public void beforeAnalysis(BeforeAnalysisAccess access) {
11+
try {
12+
RuntimeJNIAccess.register(HttpRequestBase.class);
13+
RuntimeJNIAccess.register(HttpRequestBase.class.getDeclaredField("bodyStream"));
14+
} catch (NoSuchFieldException e) {
15+
throw new RuntimeException(e);
16+
}
17+
}
18+
}
19+

src/main/resources/META-INF/native-image/software.amazon.awssdk/crt/aws-crt/jni-config.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@
174174
"name":"software.amazon.awssdk.crt.http.HttpRequest",
175175
"methods":[{"name":"<init>","parameterTypes":["java.nio.ByteBuffer","software.amazon.awssdk.crt.http.HttpRequestBodyStream"] }]
176176
},
177-
{
178-
"name":"software.amazon.awssdk.crt.http.HttpRequestBase",
179-
"fields":[{"name":"bodyStream"}]
180-
},
181177
{
182178
"name":"software.amazon.awssdk.crt.http.HttpRequestBodyStream",
183179
"methods":[{"name":"getLength","parameterTypes":[] }, {"name":"resetPosition","parameterTypes":[] }, {"name":"sendRequestBody","parameterTypes":["java.nio.ByteBuffer"] }]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Args=-H:ClassInitialization=org.slf4j:build_time
1+
Args=-H:ClassInitialization=org.slf4j:build_time --features=software.amazon.awssdk.crt.graalvm.JNIRegistrationFeature

0 commit comments

Comments
 (0)