Skip to content

Commit f47737d

Browse files
committed
improve the native image generation and added proper docs
1 parent d2fb725 commit f47737d

File tree

3 files changed

+57
-94
lines changed

3 files changed

+57
-94
lines changed

aesh/getting-started-runtime/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Launch the Maven build with:
2323

2424
For simplicity we use the Maven shade plugin to package all the dependencies into on jar, to run:
2525

26-
> java -jar target/getting-started-runtime0.1.jar --input
26+
> java -jar target/getting-started-runtime-0.1.jar --input
2727
or
28-
> java -jar target/getting-started-runtime0.1.jar --bar Foo
28+
> java -jar target/getting-started-runtime-0.1.jar --bar Foo
2929

aesh/native-runtime/README.md

+26-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
1-
# Æsh Getting Started Runtime
1+
# Æsh Native Example Runtime
22

3-
Æsh can also be set up to run just one command. It will try to parse all the parameters as normal and execute
4-
the one command specified.
3+
Here we show a simple way of using GraalVM against a Æsh runtime example to create a binary executable.
4+
For this example to work you need to have GraalVM installed and the environmental variable `GRAALVM_HOME` set to
5+
the directory it was installed.
56

6-
In this example we've created a simple command `RuntimeCommand` where we have defined two options:
7-
`input`and `bar`. If `input` is provided as a parameter, the command will query the user for an answer, else it
8-
will try to display the value of the input parameter `bar`.
7+
Note that if you use GraalVM 19 or later you also need to manually install the `native-image`binary by doing:
8+
9+
> cd $GRAALVM_HOME/bin; gu install native-image
10+
11+
To build the native image, we've created a build profile named *native*. To trigger that profile we do:
12+
13+
> mvn install -Pnative
14+
15+
This will create a binary in the target folder called *aesh-native-runtime-0.1*. Run it with:
16+
17+
> target/aesh-native-runtime-0.1
18+
19+
Note that Æsh uses reflection so it needs to generate a JSON file that is given to GraalVM to specify
20+
which classes that is. Luckily Æsh have a tool to build that file for you. In the `pom.xml` we trigger
21+
that tool before we call the native-image generation. The JSON file generated is written to `target/native_reflection.json`.
22+
23+
In this example we've created a simple command `NativeCommand` where we have defined three options:
24+
`input`, `bar` and `help`.
25+
If no options are given, the help information will be displayed.
926

1027
## Requirements
1128

1229
To compile and run you need
13-
- JDK 8 or later
30+
- JDK 8 ang GraalVM 1.0 RC12 later
1431
- Apache Maven `3.5.+`
1532

1633
## Building
1734

18-
Launch the Maven build with:
35+
Launch the Maven build with (without native):
1936

2037
> mvn install
2138
2239
## Running
2340

2441
For simplicity we use the Maven shade plugin to package all the dependencies into on jar, to run:
2542

26-
> java -jar target/getting-started-runtime0.1.jar --input
27-
or
28-
> java -jar target/getting-started-runtime0.1.jar --bar Foo
43+
> target/aesh-native-started-runtime-0.1.jar
2944

aesh/native-runtime/pom.xml

+29-81
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<groupId>org.aesh</groupId>
4747
<artifactId>aesh</artifactId>
4848
<version>${aesh.version}</version>
49-
</dependency>
49+
</dependency>
5050
</dependencies>
5151

5252
<build>
@@ -76,78 +76,12 @@
7676
</execution>
7777
</executions>
7878
</plugin>
79-
<!--
80-
<plugin>
81-
<groupId>org.apache.maven.plugins</groupId>
82-
<artifactId>maven-shade-plugin</artifactId>
83-
<version>${shade-plugin.version}</version>
84-
<executions>
85-
<execution>
86-
<phase>package</phase>
87-
<goals>
88-
<goal>shade</goal>
89-
</goals>
90-
<configuration>
91-
<artifactSet>
92-
<excludes>
93-
<exclude>org.fusesource.jansi:jansi</exclude>
94-
<exclude>org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-depchain</exclude>
95-
<exclude>junit:junit</exclude>
96-
</excludes>
97-
</artifactSet>
98-
</configuration>
99-
</execution>
100-
</executions>
101-
</plugin>
102-
-->
10379
</plugins>
10480
</build>
10581

10682
<profiles>
107-
<profile>
108-
<id>prepare</id>
109-
<activation>
110-
<property>
111-
<name>prepare</name>
112-
</property>
113-
</activation>
114-
<build>
115-
<plugins>
116-
<plugin>
117-
<groupId>org.codehaus.mojo</groupId>
118-
<artifactId>exec-maven-plugin</artifactId>
119-
<version>1.6.0</version>
120-
<executions>
121-
<execution>
122-
<id>copy</id>
123-
<phase>package</phase>
124-
<goals>
125-
<goal>exec</goal>
126-
</goals>
127-
</execution>
128-
</executions>
129-
<configuration>
130-
<executable>java</executable>
131-
<workingDirectory>target</workingDirectory>
132-
<arguments>
133-
<argument>-cp</argument>
134-
<classpath/>
135-
<argument>org.aesh.util.GraalReflectionGenerator</argument>
136-
<argument>org.acme.runtime.NativeCommand</argument>
137-
</arguments>
138-
</configuration>
139-
</plugin>
140-
</plugins>
141-
</build>
142-
</profile>
143-
14483
<profile>
14584
<id>native</id>
146-
<activation>
147-
<property>
148-
<name>native</name>
149-
</property>
150-
</activation>
15185
<build>
15286
<plugins>
15387
<plugin>
@@ -179,26 +113,40 @@
179113
<goals>
180114
<goal>exec</goal>
181115
</goals>
116+
<configuration>
117+
<executable>java</executable>
118+
<workingDirectory>target</workingDirectory>
119+
<arguments>
120+
<argument>-cp</argument>
121+
<classpath/>
122+
<argument>org.aesh.util.GraalReflectionGenerator</argument>
123+
<argument>org.acme.runtime.NativeCommand</argument>
124+
</arguments>
125+
</configuration>
126+
</execution>
127+
<execution>
128+
<id>native</id>
129+
<phase>package</phase>
130+
<goals>
131+
<goal>exec</goal>
132+
</goals>
133+
<configuration>
134+
<executable>${env.GRAALVM_HOME}/bin/native-image</executable>
135+
<workingDirectory>target</workingDirectory>
136+
<arguments>
137+
<argument>--verbose</argument>
138+
<argument>-H:+ReportUnsupportedElementsAtRuntime</argument>
139+
<argument>-H:ReflectionConfigurationFiles=native_reflection.json</argument>
140+
<argument>-jar</argument>
141+
<argument>${project.build.finalName}.jar</argument>
142+
</arguments>
143+
</configuration>
182144
</execution>
183145
</executions>
184-
<configuration>
185-
<executable>${env.GRAALVM_HOME}/bin/native-image</executable>
186-
<workingDirectory>target</workingDirectory>
187-
<arguments>
188-
<argument>--verbose</argument>
189-
<argument>-H:+ReportUnsupportedElementsAtRuntime</argument>
190-
<argument>-H:ReflectionConfigurationFiles=native_reflection.json</argument>
191-
<argument>-jar</argument>
192-
<argument>${project.build.finalName}.jar</argument>
193-
</arguments>
194-
</configuration>
195146
</plugin>
196147
</plugins>
197148
</build>
198149
</profile>
199150
</profiles>
200151

201-
202-
203-
204152
</project>

0 commit comments

Comments
 (0)