Skip to content

Commit

Permalink
add script to compile to native executable (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
neillin authored Oct 30, 2022
1 parent 0ea3dab commit b0b759d
Show file tree
Hide file tree
Showing 10 changed files with 1,405 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,19 @@ response:
"severity": "ERROR"
}
```
#### Compile to native executable with Graalvm native-image

Graalvm and its native-image are required to compile uber jar file native executable, please following the [link](https://www.graalvm.org/java/quickstart) to install latest version of Graalvm

```
mvn clean install
native-image -jar target/light-gateway.jar -o target/application
```
you can execute the generated executable with following command:

```
target/application -Dight-4j-config-dir=config/local
```


2 changes: 1 addition & 1 deletion config/local/values.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ handler.chains.default:
- audit
- sanitizer
- validator
- prefix
#- prefix
- router
- proxy

Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/versions/**</exclude>
<exclude>META-INF/native-image/io.netty/**</exclude>
<exclude>META-INF/native-image/software.amazon.awssdk/**</exclude>
</excludes>
</filter>
</filters>
Expand Down
55 changes: 55 additions & 0 deletions src/main/resources/META-INF/native-image/jni-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"name":"[Lcom.sun.management.internal.DiagnosticCommandArgumentInfo;"
},
{
"name":"[Lcom.sun.management.internal.DiagnosticCommandInfo;"
},
{
"name":"com.networknt.server.Server",
"methods":[{"name":"main","parameterTypes":["java.lang.String[]"] }]
},
{
"name":"com.sun.management.internal.DiagnosticCommandArgumentInfo",
"methods":[{"name":"<init>","parameterTypes":["java.lang.String","java.lang.String","java.lang.String","java.lang.String","boolean","boolean","boolean","int"] }]
},
{
"name":"com.sun.management.internal.DiagnosticCommandInfo",
"methods":[{"name":"<init>","parameterTypes":["java.lang.String","java.lang.String","java.lang.String","java.lang.String","java.lang.String","java.lang.String","boolean","java.util.List"] }]
},
{
"name":"java.lang.Boolean",
"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.lang.String",
"methods":[
{"name":"lastIndexOf","parameterTypes":["int"] },
{"name":"substring","parameterTypes":["int"] }
]
},
{
"name":"java.lang.System",
"methods":[
{"name":"getProperty","parameterTypes":["java.lang.String"] },
{"name":"setProperty","parameterTypes":["java.lang.String","java.lang.String"] }
]
},
{
"name":"java.util.Arrays",
"methods":[{"name":"asList","parameterTypes":["java.lang.Object[]"] }]
},
{
"name":"sun.management.VMManagementImpl",
"fields":[
{"name":"compTimeMonitoringSupport"},
{"name":"currentThreadCpuTimeSupport"},
{"name":"objectMonitorUsageSupport"},
{"name":"otherThreadCpuTimeSupport"},
{"name":"remoteDiagnosticCommandsSupport"},
{"name":"synchronizerUsageSupport"},
{"name":"threadAllocatedMemorySupport"},
{"name":"threadContentionMonitoringSupport"}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Args = -H:+ReportExceptionStackTraces \
-H:TraceClassInitialization=true \
--enable-http \
--enable-https \
--enable-url-protocols=http,https \
--report-unsupported-elements-at-runtime \
--no-fallback \
--native-image-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"type":"agent-extracted",
"classes":[
]
}
]

2 changes: 2 additions & 0 deletions src/main/resources/META-INF/native-image/proxy-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
Loading

0 comments on commit b0b759d

Please sign in to comment.