Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,13 @@ Examples requiring specific JDK versions may need `fork` and `executable` config
Examples requiring specific JDK versions may need `fork` and `executable` configuration with environment-specific paths.

Resource handling::
Examples with non-.class resources (like xref:jigsaw-examples/example_resources/README.adoc#maven-4-migration[example_resources]) need `maven-resources-plugin` configuration to copy resources from the modular source directories (`src/<module>/main`) to the target classes directories, as the hybrid compilation approach only packages compiled `.class` files by default.
Examples with non-.class resources (like xref:jigsaw-examples/example_resources/README.adoc#maven-4-migration[example_resources]) need resources copied from the modular source directories (`src/<module>/main/resources`) to the target classes directories (`target/classes/<module>/`).
+
With https://github.com/apache/maven/pull/11505[Maven Core PR #11505], this happens automatically - the resources plugin discovers resources from the modular layout and copies them to the correct location.
+
Special case: xref:jigsaw-examples/example_addExports_manifest/README.adoc#sec:maven-4-migration[example_addExports_manifest] requires a custom `MANIFEST.MF` in `src/modmain/main/resources/META-INF/`.
This example uses real source directories (not symlinks) because the `MANIFEST.MF` must be copied alongside the Java sources.
See the example's README for detailed migration notes.

Multiple module versions::
Examples requiring multiple versions of the same module (like xref:jigsaw-examples/example_layer-modules-module-resolution/README.adoc#maven-4-migration[example_layer-modules-module-resolution]) cannot use the standard Module Source Hierarchy approach, as the `<sources>` element expects one source location per module name.
Expand Down
50 changes: 50 additions & 0 deletions jigsaw-examples/example_addExports_manifest/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,53 @@ include::run-result/run.txt[]
----
include::m4/run-result/run.txt[]
----

=== Maven 4 Migration Notes

This example requires special handling for Maven 4 migration due to the `MANIFEST.MF` file that must be included in the JAR.

==== Directory Structure

Unlike most other examples that use symlinks from `m4/src/<module>/main/java` to the original sources, this example uses a real directory structure for `modmain`:

[source]
----
m4/src/modmain/main/
├── java/
│ ├── module-info.java
│ └── pkgmain/
│ └── Main.java
└── resources/
└── META-INF/
└── MANIFEST.MF
----

The `moda` module still uses a symlink since it doesn't require resources.

==== MANIFEST.MF Content

The `MANIFEST.MF` contains custom entries that are merged with the JAR tool's default manifest:

[source]
----
Add-Exports: java.base/jdk.internal.misc moda/pkgainternal
Main-Class: pkgmain.Main
----

[NOTE]
====
The standard `Manifest-Version` and `Created-By` entries are omitted from the source `MANIFEST.MF` because they are automatically added by the JAR tool.
Including them would cause duplicate entry warnings.
====

==== Required Maven PRs

This example depends on two Maven improvements:

. https://github.com/apache/maven/pull/11505[Maven Core PR #11505]: Automatic module-aware resource handling
** Automatically discovers resources from `src/<module>/main/resources`
** Copies them to `target/classes/<module>/`

. https://github.com/apache/maven-jar-plugin/pull/508[JAR Plugin PR #508]: Automatic JAR-per-module creation
** Creates individual JARs for each module (e.g., `modmain-1.0-SNAPSHOT.jar`)
** Reads `Main-Class` from the module's `MANIFEST.MF` in `target/classes/<module>/META-INF/`
40 changes: 6 additions & 34 deletions jigsaw-examples/example_addExports_manifest/m4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
</sources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -46,40 +51,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<executions>
<!-- Skip default JAR creation -->
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
<!-- Create module-specific JARs -->
<execution>
<id>moda</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/moda</classesDirectory>
<classifier>moda</classifier>
</configuration>
</execution>
<execution>
<id>modmain</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modmain</classesDirectory>
<classifier>modmain</classifier>
<archive>
<manifestFile>src/modmain/main/java/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</execution>
</executions>
<version>4.0.0-beta-2-PR508-SNAPSHOT</version>
</plugin>
</plugins>
</build>
Expand Down
2 changes: 1 addition & 1 deletion jigsaw-examples/example_addExports_manifest/m4/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ mkdir -p run-result
"${JAVA11_HOME}/bin/java" ${JAVA_OPTIONS} \
--add-modules moda \
--module-path target \
-jar target/example_addExports_manifest-m4-1.0-SNAPSHOT-modmain.jar 2>&1 | normalize | tee -a run-result/run.txt | myecho
-jar target/modmain-1.0-SNAPSHOT.jar 2>&1 | normalize | tee -a run-result/run.txt | myecho

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
open module modmain { // allow reflective access, currently used in the example_jerry-mouse
requires moda;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package pkgmain;

import jdk.internal.misc.SharedSecrets;

/**
* This class cannot be compiled in Eclipse as compiler options --add-exports are needed.
* See compile.sh for details.
*
* But if compilation has taken place outside Eclipse with the script,
* the modular JARs can be found in .../mlib
*
* The Eclipse launch files takes the compiled code from there and can be run in Eclipse.
*/

public class Main {
public static void main(String[] args) {
// Compiler and also Runtime option needed: --add-exports java.base/jdk.internal.misc=modmain
SharedSecrets secrets = new SharedSecrets();
System.out.println("Do you want to know a secret: " + secrets.getClass().getName());

// Compiler and also Runtime option needed: --add-exports moda/pkgainternal=modmain
System.out.println(new pkgainternal.A().doIt());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add-Exports: java.base/jdk.internal.misc moda/pkgainternal
Main-Class: pkgmain.Main
43 changes: 1 addition & 42 deletions jigsaw-examples/example_addReads_addExports/m4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,48 +49,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<executions>
<!-- Skip default JAR creation -->
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
<!-- Create module-specific JARs -->
<execution>
<id>modb</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modb</classesDirectory>
<classifier>modb</classifier>
</configuration>
</execution>
<execution>
<id>modc</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modc</classesDirectory>
<classifier>modc</classifier>
</configuration>
</execution>
<execution>
<id>modmain</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modmain</classesDirectory>
<classifier>modmain</classifier>
</configuration>
</execution>
</executions>
<version>4.0.0-beta-2-PR508-SNAPSHOT</version>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<executions>
<!-- Skip default JAR creation -->
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
<!-- Create module-specific JARs -->
<execution>
<id>modb</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modb</classesDirectory>
<classifier>modb</classifier>
</configuration>
</execution>
<execution>
<id>modmain</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modmain</classesDirectory>
<classifier>modmain</classifier>
</configuration>
</execution>
</executions>
<version>4.0.0-beta-2-PR508-SNAPSHOT</version>
</plugin>
</plugins>
</build>
Expand Down
43 changes: 1 addition & 42 deletions jigsaw-examples/example_annotations/m4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<executions>
<!-- Skip default JAR creation -->
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
<!-- Create module-specific JARs -->
<execution>
<id>mod.annotations</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/mod.annotations</classesDirectory>
<classifier>mod.annotations</classifier>
</configuration>
</execution>
<execution>
<id>modb</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modb</classesDirectory>
<classifier>modb</classifier>
</configuration>
</execution>
<execution>
<id>modmain</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modmain</classesDirectory>
<classifier>modmain</classifier>
</configuration>
</execution>
</executions>
<version>4.0.0-beta-2-PR508-SNAPSHOT</version>
</plugin>
</plugins>
</build>
Expand Down
21 changes: 1 addition & 20 deletions jigsaw-examples/example_automatic-module-logging/m4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<executions>
<!-- Skip default JAR creation -->
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
<!-- Create module-specific JARs -->
<execution>
<id>modmain</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modmain</classesDirectory>
<classifier>modmain</classifier>
</configuration>
</execution>
</executions>
<version>4.0.0-beta-2-PR508-SNAPSHOT</version>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<executions>
<!-- Skip default JAR creation -->
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
<!-- Create module-specific JARs -->
<execution>
<id>modb</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modb</classesDirectory>
<classifier>modb</classifier>
</configuration>
</execution>
<execution>
<id>modmain</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modmain</classesDirectory>
<classifier>modmain</classifier>
</configuration>
</execution>
</executions>
<version>4.0.0-beta-2-PR508-SNAPSHOT</version>
</plugin>
</plugins>
</build>
Expand Down
Loading
Loading