Skip to content

Commit fada11d

Browse files
committed
Provide steps to run the maven example on module path and class path (without a fat jar).
Remove maven-assembly-plugin. Add maven package step copying all runtime dependencies to a directory. Set Main-Class attribute in the JAR manifest.
1 parent 9bc8ff3 commit fada11d

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

docs/user/README.md

+43-12
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ See how to install GraalVM on the [Downloads page](https://www.graalvm.org/downl
104104
</properties>
105105
```
106106
107-
4. Add the regular Maven plugins for compiling and assembling the project into a JAR file with all dependencies to your _pom.xml_ file:
107+
4. Add the Maven plugins for compiling the project into a JAR file and copying all runtime dependencies into a directory to your _pom.xml_ file:
108108
```xml
109109
<build>
110110
<plugins>
@@ -118,42 +118,73 @@ See how to install GraalVM on the [Downloads page](https://www.graalvm.org/downl
118118
</plugin>
119119
<plugin>
120120
<groupId>org.apache.maven.plugins</groupId>
121-
<artifactId>maven-assembly-plugin</artifactId>
122-
<version>3.7.1</version>
121+
<artifactId>maven-jar-plugin</artifactId>
122+
<version>3.4.2</version>
123123
<configuration>
124124
<archive>
125125
<manifest>
126126
<mainClass>com.example.App</mainClass>
127127
</manifest>
128128
</archive>
129-
<descriptorRefs>
130-
<descriptorRef>jar-with-dependencies</descriptorRef>
131-
</descriptorRefs>
132129
</configuration>
130+
</plugin>
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-dependency-plugin</artifactId>
134+
<version>3.8.0</version>
133135
<executions>
134136
<execution>
135-
<id>make-assembly</id>
137+
<id>copy-dependencies</id>
136138
<phase>package</phase>
137139
<goals>
138-
<goal>single</goal>
140+
<goal>copy-dependencies</goal>
139141
</goals>
142+
<configuration>
143+
<outputDirectory>${project.build.directory}/modules</outputDirectory>
144+
<includeScope>runtime</includeScope>
145+
<includeTypes>jar</includeTypes>
146+
</configuration>
140147
</execution>
141148
</executions>
142149
</plugin>
143150
</plugins>
144151
</build>
145152
```
146153
147-
5. Package the project and run the application:
154+
5. (Optional.) Add _module-info.java_ to your application.
155+
If you would like to run your application on the module path, create a _module-info.java_ file in _src/main/java_ with the following contents:
156+
```java
157+
module com.example {
158+
requires org.graalvm.polyglot;
159+
}
160+
```
161+
162+
6. Compile and package the project:
148163
```bash
149164
mvn clean package
150165
```
166+
167+
7. Run the application using GraalVM or another compatible JDK.
168+
If you've included _module-info.java_ in your project (step 5), you can now run the application on the module path, using one of the following commands:
169+
```bash
170+
java --module-path target/modules:target/helloworld-1.0-SNAPSHOT.jar --module com.example/com.example.App "GraalVM"
171+
java -p target/modules:target/helloworld-1.0-SNAPSHOT.jar -m com.example/com.example.App "GraalVM"
172+
```
173+
Otherwise, you can run with the dependencies on the module path and the application on the class path:
174+
```bash
175+
java --module-path target/modules --add-modules=org.graalvm.polyglot -cp target/helloworld-1.0-SNAPSHOT.jar com.example.App "GraalVM"
176+
java --module-path target/modules --add-modules=org.graalvm.polyglot -jar target/helloworld-1.0-SNAPSHOT.jar "GraalVM"
177+
```
178+
Alternatively, you can run with everything on the class path as well (in this case you need to use `*` or specify all JAR files):
151179
```bash
152-
java -jar target/helloworld-1.0-SNAPSHOT-jar-with-dependencies.jar GraalVM
180+
java -cp "target/modules/*:target/helloworld-1.0-SNAPSHOT.jar" com.example.App "GraalVM"
181+
# or using shell expansion:
182+
java -cp "$(find target/modules -name '*.jar' | tr '\n' :)target/helloworld-1.0-SNAPSHOT.jar" com.example.App "GraalVM"
183+
java -cp "$(printf %s: target/modules/*.jar)target/helloworld-1.0-SNAPSHOT.jar" com.example.App "GraalVM"
153184
```
154185
155-
A single JAR with all dependencies was created from language libraries.
156-
However, we recommend splitting and using Java modules on the module path, especially if you would like to compile this application ahead of time with GraalVM Native Image.
186+
> Note: We discourage bundling all dependencies into a single "fat" JAR (for example, using the Maven Assembly plugin) as it can cause issues and prevent ahead-of-time compilation with [GraalVM Native Image](https://www.graalvm.org/reference-manual/native-image/).
187+
> Instead, we recommend using the original, separate JAR files for all `org.graalvm.*` dependencies, preferably on the module path.
157188
Learn more in the [Guide to Embedding Languages](https://www.graalvm.org/reference-manual/embed-languages/#dependency-setup).
158189
159190
The source code unit can be represented with a String, as shown in the example, a file, read from URL, and [other means](https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/Source.html).

0 commit comments

Comments
 (0)