diff --git a/.claude/transformations/maven-4-migration.md b/.claude/transformations/maven-4-migration.md index ad7baa5b..435f9f05 100644 --- a/.claude/transformations/maven-4-migration.md +++ b/.claude/transformations/maven-4-migration.md @@ -85,13 +85,13 @@ example_foo/ │ │ └── modb/ │ │ └── main/ │ │ └── java -> ../../../../src/modb # Symlink to module source -│ ├── mlib/ # Module JARs (separate from ../mlib) +│ ├── mlib/ # Module JARs (Phase 1 only - not used in Phase 2) │ ├── run-result/ # Runtime output (for verification) -│ ├── target/ # Maven build output -│ ├── .gitignore # Ignore build artifacts (target/, mlib/, run-result/) +│ ├── target/ # Maven build output (Phase 2: also contains JARs) +│ ├── .gitignore # Ignore build artifacts (Phase 1: target/, mlib/, run-result/; Phase 2: target/, run-result/) │ ├── clean.sh # Clean m4 artifacts -│ ├── compile.sh # Maven compile + jar packaging -│ ├── run.sh # Execution (uses m4/mlib) +│ ├── compile.sh # Phase 1: Maven compile + jar; Phase 2: Maven package +│ ├── run.sh # Phase 1: uses mlib; Phase 2: uses target │ ├── verify.sh # Golden master verification │ └── javadoc.sh # Maven javadoc wrapper (optional) ├── m3/ # (Future) Maven 3 alternative approach @@ -384,16 +384,106 @@ popd >/dev/null 2>&1 - Creates JARs directly to `mlib/` (not `../mlib/`) for complete separation - Uses same JAR creation pattern as original compile.sh -**Phase 2: Full Maven (Future)** +**Phase 2: Maven JAR Plugin (Current Best Practice)** -Once Maven plugins prove compatible with JPMS: +Replace manual JAR creation with maven-jar-plugin for cleaner Maven integration: ```bash #!/usr/bin/env bash set -eu -o pipefail -echo "=== Maven 4 Compile (Full Maven) ===" +# shellcheck source=../../env.sh +source ../../env.sh + +# Ensure we're using Maven 4 +if [ -z "${M4_HOME:-}" ]; then + echo "ERROR: M4_HOME is not set. Please configure it in .envrc or env.sh" + exit 1 +fi + +# Maven 4 requires Java 17+ to run +if [ -n "${JAVA17_HOME:-}" ]; then + export JAVA_HOME="${JAVA17_HOME}" +fi + +# Add Maven 4 to PATH +export PATH="${M4_HOME}/bin:${PATH}" + +echo "mvn --version" +mvn --version echo + +echo "mvn clean package" +echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" +echo "(JARs are created by maven-jar-plugin in target/ directory)" +mvn clean package +``` + +**Benefits**: +- Eliminates manual JAR creation loop +- JARs created directly in `target/` directory by Maven +- Simpler script - just `mvn clean package` +- No need for `mlib/` directory +- Follows standard Maven conventions + +**POM Configuration**: + +Add maven-jar-plugin to create module-specific JARs: + +```xml + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + + +``` + +**JAR Naming Convention**: +- Pattern: `${artifactId}-${version}-${classifier}.jar` +- Example: `example-requires-exports-m4-1.0-SNAPSHOT-modmain.jar` +- Location: `target/` directory +- Java's `--module-path target` automatically finds these JARs + +**Phase 3: Full Maven (Future)** + +Once all examples migrated to maven-jar-plugin, scripts could be further simplified: + +```bash +#!/usr/bin/env bash +set -eu -o pipefail + +echo "=== Maven 4 Build ===" mvn --version echo mvn clean package @@ -404,6 +494,8 @@ echo "✅ Build complete" Execute the example using artifacts from Maven build (stays close to original run.sh): +**Phase 1: Using mlib/ directory (Hybrid Approach)** + ```bash #!/usr/bin/env bash set -eu -o pipefail @@ -424,9 +516,33 @@ mkdir -p run-result "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho ``` +**Phase 2: Using target/ directory (Maven JAR Plugin)** + +```bash +#!/usr/bin/env bash +set -eu -o pipefail + +# shellcheck source=../../env.sh +source ../../env.sh + +# Show Java version for user information +echo "Using Java version:" +"${JAVA_HOME}/bin/java" -version +echo + +# Create run-result directory if it doesn't exist +mkdir -p run-result + +# Run the Java code, save output to run-result/run.txt, and display with highlighting +# JARs are now in target/ (created by maven-jar-plugin) +# shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +``` + **Important**: - Copy structure from original `run.sh` to stay close to original -- Use `mlib` (not `../mlib`) since artifacts are in m4/mlib +- **Phase 1**: Use `mlib` (not `../mlib`) since artifacts are in m4/mlib +- **Phase 2**: Use `target` since JARs are created directly in target/ by maven-jar-plugin - Preserve any special JVM flags from original (--add-exports, --add-reads, --add-modules, etc.) - No M4_HOME needed here - only Maven runtime uses it - Output to `run-result/run.txt` for golden master verification @@ -504,6 +620,8 @@ fi Clean all m4 build artifacts: +**Phase 1: Hybrid Approach (with mlib/)** + ```bash #!/usr/bin/env bash rm -rf target @@ -511,7 +629,17 @@ rm -rf mlib rm -rf run-result ``` -**Note**: Simple cleanup matching original pattern - removes Maven output, JARs, and runtime results +**Phase 2: Maven JAR Plugin (no mlib/)** + +```bash +#!/usr/bin/env bash +rm -rf target +rm -rf run-result +``` + +**Note**: +- **Phase 1**: Removes Maven output (target/), manually created JARs (mlib/), and runtime results (run-result/) +- **Phase 2**: Simpler - only removes Maven output (target/) and runtime results (run-result/), no mlib/ needed ### javadoc.sh - Documentation Wrapper (Optional) @@ -564,12 +692,23 @@ echo "✅ Javadoc generated in target/site/apidocs" ``` 5. **Create .gitignore**: + + **Phase 1: Hybrid Approach** ```bash # Create .gitignore to exclude build artifacts cat > .gitignore << 'EOF' target/ mlib/ run-result/ +EOF + ``` + + **Phase 2: Maven JAR Plugin** + ```bash + # Create .gitignore to exclude build artifacts (no mlib needed) + cat > .gitignore << 'EOF' +target/ +run-result/ EOF ``` @@ -579,32 +718,47 @@ EOF - Declare each module with matching `` name and `` path - Add dependencies if needed - Configure compiler plugin for JPMS + - **Phase 2**: Add maven-jar-plugin configuration (see Phase 2 compile.sh section above) - Adjust release version per example requirements - Include test sources declaration if example has tests -6. **Create compile.sh**: +7. **Create compile.sh**: + + **Phase 1: Hybrid Approach** - Follow hybrid approach (Maven compile + traditional jar) - Inspect original compile.sh for jar commands - Adapt paths to Maven's target/ structure - - Copy JARs to ../mlib for compatibility + - Create JARs in mlib/ + + **Phase 2: Maven JAR Plugin** (Recommended) + - Use `mvn clean package` instead of `mvn clean compile` + - Remove manual JAR creation loop + - JARs created automatically in target/ by maven-jar-plugin + +8. **Create run.sh**: -7. **Create run.sh**: + **Phase 1: Using mlib/** - Copy module path configuration from original - - Adjust paths to use ../mlib (populated by compile.sh) + - Adjust paths to use `mlib` (populated by compile.sh) - Preserve any special JVM flags -8. **Create verify.sh**: + **Phase 2: Using target/** + - Change `--module-path mlib` to `--module-path target` + - JARs automatically found in target/ directory + - Preserve any special JVM flags + +9. **Create verify.sh**: - Integrate with golden master framework - Reuse existing expected-result.txt - Follow verification script pattern above -9. **Test Migration**: +10. **Test Migration**: ```bash cd m4 ./verify.sh ``` -10. **Update Example README**: Add both Maven 4 output section and Maven 4 Migration section to the example's README.adoc: +11. **Update Example README**: Add both Maven 4 output section and Maven 4 Migration section to the example's README.adoc: a. Add the Maven 4 output section (if not already present): ```adoc @@ -650,7 +804,78 @@ EOF This documents the migration completion and shows that Maven 4 produces equivalent output. For examples with special requirements, it provides valuable documentation for similar migrations. -11. **Document Issues**: Note any JPMS/Maven plugin compatibility issues for future resolution +12. **Document Issues**: Note any JPMS/Maven plugin compatibility issues for future resolution + +### Migrating from Phase 1 (Hybrid) to Phase 2 (Maven JAR Plugin) + +To migrate an existing Phase 1 example to Phase 2: + +1. **Update pom.xml**: + Add maven-jar-plugin configuration with one execution per module: + ```xml + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + default-jar + none + + + + modmain + package + jar + + ${project.build.outputDirectory}/modmain + modmain + + + + + ``` + +2. **Update compile.sh**: + Replace: + ```bash + mvn clean compile + # ... JAR creation loop ... + ``` + With: + ```bash + mvn clean package + ``` + Remove the `mkdir -p mlib` and the entire JAR creation loop. + +3. **Update run*.sh scripts**: + Change all occurrences of `--module-path mlib` to `--module-path target` + +4. **Update .gitignore**: + Remove the `mlib/` line + +5. **Update clean.sh**: + Remove the `rm -rf mlib` line + +6. **Update documentation**: + Check the example's README.adoc for any `mlib` references and update them: + ```bash + grep -n "mlib" ../README.adoc + ``` + Replace `mlib` references with `target` where appropriate. + Note: Most examples reference `mlib` in their Maven 4 Migration sections if they document directory structure. + +7. **Test the migration**: + ```bash + ./clean.sh + ./verify.sh + ``` + +8. **Verify JARs are in target/**: + ```bash + ls -la target/*.jar + ``` + Should show files like `example-foo-m4-1.0-SNAPSHOT-modmain.jar` ### Example Selection Criteria @@ -744,6 +969,17 @@ A migration is considered successful when: ## Reference Examples -Once first examples are migrated, list them here as references: +### Phase 2 Migrations (Maven JAR Plugin) + +Examples fully migrated to maven-jar-plugin (no manual JAR creation): + +- **example_requires_exports** - 3 modules (modmain, modb, modc) - Standard multi-module example +- **example_annotations** - 3 modules (mod.annotations, modb, modmain) - Demonstrates module with dot in name +- **example_hiddenmain** - 1 module (modmain) - Single module example with multiple main classes + +### Phase 1 Migrations (Hybrid Approach) + +Examples using Maven compile + manual JAR creation (33 examples total): -- (TBD - will be populated as migrations complete) \ No newline at end of file +- See `git log` for full list of Phase 1 migrations +- These examples are candidates for Phase 2 migration \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 08e08ea5..2f306ad8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Install shellcheck run: | @@ -38,7 +38,7 @@ jobs: run: git config --global core.autocrlf false - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Set up JDK 8 (non macOS) id: setup-jdk8 @@ -188,7 +188,7 @@ jobs: run: git config --global core.autocrlf false - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Set up JDK 11 id: setup-jdk11 @@ -207,7 +207,9 @@ jobs: - name: Set up Maven 4 uses: stCarolas/setup-maven@v5 with: - maven-version: '4.0.0-rc-4' + # tag::maven-4-version[] + maven-version: '4.0.0-rc-5' + # end::maven-4-version[] - name: Create .envrc with Java and Maven paths shell: bash @@ -345,7 +347,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Set up JDK 17 uses: actions/setup-java@v4 @@ -368,7 +370,7 @@ jobs: continue-on-error: true - name: Generate documentation - run: ./mvnw verify + run: ./mvnw verify -Dgithub.branch=${{ github.head_ref || github.ref_name }} - name: Create index.html from README.html run: cp target/generated-docs/README.html target/generated-docs/index.html @@ -380,33 +382,46 @@ jobs: path: target/generated-docs retention-days: 30 - - name: Deploy to Netlify (Preview) - if: github.event_name == 'pull_request' + - name: Set Netlify alias + if: github.ref != 'refs/heads/main' + id: netlify-alias + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + echo "alias=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT + else + # Use branch name, sanitize it for Netlify (replace / with -) + BRANCH_NAME="${{ github.ref_name }}" + SANITIZED_BRANCH=$(echo "$BRANCH_NAME" | sed 's/\//-/g') + echo "alias=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT + fi + + - name: Deploy to Netlify (branches and PRs) + if: github.ref != 'refs/heads/main' + id: netlify-deploy uses: nwtgck/actions-netlify@v3 with: publish-dir: './target/generated-docs' production-deploy: false github-token: ${{ secrets.GITHUB_TOKEN }} - deploy-message: "Deploy from GitHub Actions - PR #${{ github.event.pull_request.number }}" + deploy-message: "Deploy from GitHub Actions - ${{ github.event.head_commit.message || github.event.pull_request.title }}" enable-pull-request-comment: true enable-commit-comment: false overwrites-pull-request-comment: true + alias: ${{ steps.netlify-alias.outputs.alias }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} - - name: Deploy to Netlify (Branch Preview) - if: github.event_name == 'push' && github.ref != 'refs/heads/main' - uses: nwtgck/actions-netlify@v3 - with: - publish-dir: './target/generated-docs' - production-deploy: false - github-token: ${{ secrets.GITHUB_TOKEN }} - deploy-message: "Deploy from GitHub Actions - branch ${{ github.ref_name }}" - alias: ${{ github.ref_name }} - env: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + - name: Display Netlify URL + if: github.ref != 'refs/heads/main' + run: | + echo "### 🚀 Netlify Deployment" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "✅ **Deployed successfully!**" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "🔗 **URL:** ${{ steps.netlify-deploy.outputs.deploy-url }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "📝 **Alias:** \`${{ steps.netlify-alias.outputs.alias }}\`" >> $GITHUB_STEP_SUMMARY - name: Upload to GitHub Pages if: github.event_name == 'push' diff --git a/.gitignore b/.gitignore index 78a593c0..348acef0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ # IDE configuration .idea/ +*.iml +.vscode/ # Downloaded files .m2/ @@ -21,4 +23,7 @@ *.html # Maven artifacts -target/ \ No newline at end of file +target/ + +# Log files +*.log \ No newline at end of file diff --git a/README.adoc b/README.adoc index ac6860cb..c13dbbc5 100755 --- a/README.adoc +++ b/README.adoc @@ -7,55 +7,49 @@ ifdef::env-github[] :caution-caption: :fire: :warning-caption: :warning: endif::[] +:example-base: jigsaw-examples [IMPORTANT] .Authors ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ (Maven for short) in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as a https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== == What is this about? -This is a example suite for Java 9 jigsaw modules. -Many aspects of the new Java 9 Jigsaw modules as defined in https://openjdk.java.net/projects/jigsaw/[Project Jigsaw] by https://www.jcp.org/en/jsr/detail?id=376[JSR 376] and https://openjdk.java.net/jeps/261[JEP 261]. +This is an example suite for Java Modules. +It initially demonstrates many aspects of Java Modules as defined in https://openjdk.java.net/projects/jigsaw/[Project Jigsaw] by https://www.jcp.org/en/jsr/detail?id=376[JSR 376] and https://openjdk.java.net/jeps/261[JEP 261]. -All the examples have been successfully tested with Windows (64bit), Linux and MacOSX - running the <>. -Originally developed for Java 9 (which introduced JPMS), the examples are continuously updated for current Java versions. - -*Build Tool Wrappers:* All Maven and Gradle examples now include build tool wrappers, so manual installation of Maven or Gradle is no longer required: - -* Maven examples include *Maven Wrapper 3.9.11* (mvnw/mvnw.cmd) -* Gradle example includes *Gradle Wrapper 9.1.0* (gradlew/gradlew.cmd) - requires *JDK 17 or later* - -[TIP] +[NOTE] +.Jigsaw / JPMS have become Java Modules ==== -Use a local Maven repository to avoid polluting your global one, set a repository location in the top level directory: - -[source,bash] ----- -export MAVEN_OPTS="-Dmaven.repo.local=${PWD}/.m2/repository" ----- - -Note that this overrides any other settings, e.g., by `mvn_settings.xml`. +Java Modules were introduced in Java 9 as part of Project Jigsaw. +The term "Jigsaw" was commonly used during the development phase and early adoption. +However, the official terminology has since shifted to "Java Modules" or "Java Platform Module System (JPMS)". +In this documentation, both terms may be used interchangeably, but "Java Modules" is the preferred term in current contexts. ==== +Meanwhile, we extended many examples to work (currently) with Maven 4 to demonstrate the current state of the art in terms of Maven support for Java Modules. + == Setup . Clone this repository . Ensure you meet the _Minimal Requirements_ . Then either follow the _Quick Setup_ or the _Full Setup_ -. Finally _Run Examples_ +. Finally, _Run Examples_ +[[sec:minimal-requirements]] === Minimal Requirements -. If running on Windows, install a bash, like for example https://babun.github.io/[Babun] or https://gitforwindows.org/[git bash] +. If running on Windows, install a bash, like, for example, https://babun.github.io/[Babun] or https://gitforwindows.org/[git bash] . Install Java JDKs: -** See <> for the recommended version for full CI (automated testing) compatibility -** For xref:jigsaw-examples/example_gradle-project/README.adoc[Gradle example]: Java 17 or later (required by Gradle 9.x) -** For xref:jigsaw-examples/example_compile-target-jdk8/README.adoc[cross-compilation example]: Java 8 +** See <> for the recommended version for full CI (automated testing) compatibility. +** For Maven 4 and xref:jigsaw-examples/example_gradle-project/README.adoc[Gradle example]: Java 17 or later is required. +** For the xref:jigsaw-examples/example_compile-target-jdk8/README.adoc[cross-compilation example]: Java 8. +. Install Maven 4 if you want to run the Maven 4 migrated examples (cf. <> and <>). [[recommended-jdk]] [NOTE] @@ -63,7 +57,7 @@ Note that this overrides any other settings, e.g., by `mvn_settings.xml`. ==== The following JDK version is *strongly recommended* for full compatibility with CI and automated testing: -[source,yaml] +[source,yaml,indent=0] ---- include::.github/workflows/build.yml[tag=java-version-minimal] ---- @@ -95,7 +89,7 @@ cp .envrc-template .envrc Then either: * *Option 1:* Source it manually before running examples: `source .envrc` -* *Option 2:* Use https://direnv.net/[direnv] to automatically load environment when entering this directory +* *Option 2:* Use https://direnv.net/[direnv] to automatically load the environment when entering this directory [NOTE] .SDKMAN Users @@ -111,8 +105,8 @@ If you experience version conflicts, either disable `sdkman_auto_env` or ensure . Edit file `env.sh` to configure `JAVA_HOME`, `JAVA_HOME_JDK8`, `GRAPHVIZ_HOME`, and `DEPVIS_HOME` (see TODO markers in the file) ** See <> for the recommended `JAVA_HOME` value . Also edit file `env.sh` to configure the path separator. -If run on Windows, use \; (a blackslash quoting a ;). -If you run all stuff on *nix, use a colon : . +If run on Windows, use `\;` (a blackslash quoting a `;`). +If you run all stuff on *nix, use a colon `:` . === Running Examples @@ -157,16 +151,15 @@ cd jigsaw-examples [[golden-master-testing]] === Golden Master Testing -Most examples in this repository use golden master testing (also known as characterization testing or approval testing) to ensure output consistency. +Most examples in this repository use golden master testing, also known as characterization testing or approval testing, to ensure output consistency. This technique captures the expected output of a program and compares it against actual output during subsequent runs. -*How it works in this repository:* - +How it works in this repository:: * Each example with golden master testing has an `expected-result/run.txt` file containing the captured expected output * When you run `./verify.sh` in an example directory, it executes the example and compares the actual output (saved to `run-result/run.txt`) with the expected output * The test passes if both outputs match exactly -*Why some examples don't have golden master testing:* +Why some examples don't have a golden master testing:: Examples that use build tools (Maven, Gradle) or frameworks (Spring Boot) typically produce output that varies between runs. This includes timestamps, absolute file paths, download progress messages, port numbers, and environment-specific information. @@ -174,20 +167,39 @@ For these examples, manual verification or integration tests are more appropriat === Additional information -All examples have been tested with the <> on Windows, Linux, and macOS. -The examples were originally developed with Java 9 (which introduced JPMS) and have been continuously updated to work with current LTS versions. +==== Shell based Build + Excution + +Originally, the examples were using shell scripts to compile, execute and create additional artifacts, e.g., Java Docs. +All examples run with scripts which have been tested with bash only. + +==== Operating Systems + +All the examples have been successfully tested with Windows (64bit), Linux and macOS - running the <>. +Originally developed for Java 9, which introduced Java Modules, the examples are frequently updated for current Java versions. + +==== Build tool usage + +For convenience and automatic testing, other (migrated) examples come with build scripts which call the respective build tool. -*Using Build Tool Wrappers:* +_Important_: Set `JAVA_HOME` (or `JAVA17_HOME` separately) to JDK 17+ before running Maven 4 or Gradle (Wrapper): `export JAVA_HOME=/path/to/jdk17` (or use `JAVA_HOME=... ./gradlew ...`). Maven Wrapper examples only require JDK 11+ as they use Mavne 3. +Build Tool Wrappers:: +All original Maven and Gradle examples now include build tool wrappers, so manual installation of Maven or Gradle is no longer required (to execute then): * For Maven examples: Use `./mvnw` (Unix/Mac) or `mvnw.cmd` (Windows) instead of `mvn` * For Gradle example: Use `./gradlew` (Unix/Mac) or `gradlew.cmd` (Windows) instead of `gradle` -** *Important*: Set `JAVA_HOME` to JDK 17+ before running: `export JAVA_HOME=/path/to/jdk17` (or use `JAVA_HOME=... ./gradlew ...`) -[NOTE] +Maven 4 Builds:: As we simply want to use Maven 4 and to switch (minor) versions, a local installation of Maven 4 is required (cf. <>). + +[TIP] ==== -All scripts have been tested with bash only. -There might be minor issues with the *.sh scripts whenever they call each other. -To be sure, you should use all of these clean, compile, run, test etc. scripts in a bash. +Use a local Maven repository to avoid polluting your global one, set a repository location in the top level directory: + +[source,bash] +---- +export MAVEN_OPTS="-Dmaven.repo.local=${PWD}/.m2/repository" +---- + +Note that this overrides any other settings, e.g., by `mvn_settings.xml`. ==== == Overall conventions @@ -213,6 +225,21 @@ Corresponding JAR files are in `example_.../patchlib`. Many examples have been migrated to Maven 4 using the new https://maven.apache.org/plugins-archives/maven-compiler-plugin-LATEST-4.x/modules.html[Module Source Hierarchy] layout. The Maven 4 builds are located in `m4/` subdirectories within each example. +[[recommended-maven4]] +[NOTE] +.Recommended Maven 4 Version +==== +The following Maven 4 version is used for CI and automated testing: + +[source,yaml,indent=0] +---- +include::.github/workflows/build.yml[tag=maven-4-version] +---- + +Set `M4_HOME` to point to this version. +For SDKMAN users: `sdk install maven 4...` (use the version shown above). +==== + === Standard Migration Approach and Defaults For most examples, the Maven 4 migration follows a straightforward pattern. @@ -431,7 +458,7 @@ Migration attempted but not yet complete. *N/A*:: Not applicable. -Example uses Maven/Gradle directly, or migration is not relevant to JPMS features. +Example uses Maven/Gradle directly, or migration is not relevant to Java Modules features. Click the status icon to jump to the example's Maven 4 Migration section for details. **** @@ -444,12 +471,12 @@ Click the status icon to jump to the example's Maven 4 Migration section for det | xref:jigsaw-examples/example_naming-modules/README.adoc[naming-modules] | Which naming conventions exist for modules? Which names are not allowed? | -| xref:jigsaw-examples/example_naming-modules/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_naming-modules/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_naming-modules/m4/[code] | xref:jigsaw-examples/example_annotations/README.adoc[annotations] | How can one specify annotations and deprecation for modules? | image:jigsaw-examples/example_annotations/moduledependencies.png[width=200,link=jigsaw-examples/example_annotations/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_annotations/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_annotations/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_annotations/m4/[code] 4+| *Examples on basic module reads and exports attributes* @@ -458,35 +485,35 @@ Click the status icon to jump to the example's Maven 4 Migration section for det Relates to all other examples in this section. | image:jigsaw-examples/example_requires_exports_requires-transitive_exports-to/moduledependencies.png[width=200,link=jigsaw-examples/example_requires_exports_requires-transitive_exports-to/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_requires_exports_requires-transitive_exports-to/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_requires_exports_requires-transitive_exports-to/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_requires_exports_requires-transitive_exports-to/m4/[code] | xref:jigsaw-examples/example_requires-static/README.adoc[requires-static] | How does requires static look like? Relates to all other examples in this section. | image:jigsaw-examples/example_requires-static/moduledependencies.png[width=200,link=jigsaw-examples/example_requires-static/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_requires-static/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_requires-static/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_requires-static/m4/[code] | xref:jigsaw-examples/example_requires_exports/README.adoc[requires_exports] | How does requires and exports look like? Relates to all other examples in this section. | image:jigsaw-examples/example_requires_exports/moduledependencies.png[width=200,link=jigsaw-examples/example_requires_exports/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_requires_exports/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_requires_exports/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_requires_exports/m4/[code] | xref:jigsaw-examples/example_requires_exports-to/README.adoc[requires_exports-to] | How does requires and qualified exports look like? Relates to all other examples in this section. | image:jigsaw-examples/example_requires_exports-to/moduledependencies.png[width=200,link=jigsaw-examples/example_requires_exports-to/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_requires_exports-to/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_requires_exports-to/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_requires_exports-to/m4/[code] | xref:jigsaw-examples/example_reflection/README.adoc[reflection] | How do reflection calls look like? Relates to all other examples in this section. | image:jigsaw-examples/example_reflection/moduledependencies.png[width=200,link=jigsaw-examples/example_reflection/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_reflection/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_reflection/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_reflection/m4/[code] 4+| *Examples on dynamic binding with uses/provides* | xref:jigsaw-examples/example_uses-provides/README.adoc[uses-provides] @@ -494,14 +521,14 @@ Relates to all other examples in this section. Relates to all other examples in this section. | image:jigsaw-examples/example_uses-provides/moduledependencies.png[width=200,link=jigsaw-examples/example_uses-provides/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_uses-provides/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_uses-provides/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_uses-provides/m4/[code] | xref:jigsaw-examples/example_uses-provides_uses-in-client/README.adoc[uses-provides_uses-in-client] | How does uses-provides look like, when uses is separated from the interface? Relates to all other examples in this section. | image:jigsaw-examples/example_uses-provides_uses-in-client/moduledependencies.png[width=200,link=jigsaw-examples/example_uses-provides_uses-in-client/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_uses-provides_uses-in-client/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_uses-provides_uses-in-client/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_uses-provides_uses-in-client/m4/[code] 4+| *Examples on accessibility and (non) exported packages* @@ -510,21 +537,21 @@ Relates to all other examples in this section. Relates to all other examples in this section. | image:jigsaw-examples/example_derived_private-package-protected/moduledependencies.png[width=200,link=jigsaw-examples/example_derived_private-package-protected/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_derived_private-package-protected/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_derived_private-package-protected/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_derived_private-package-protected/m4/[code] | xref:jigsaw-examples/example_exceptions/README.adoc[exceptions] | What happens, when exceptions are thrown to classes outside the module but their package is not exported? Relates to all other examples in this section. | image:jigsaw-examples/example_exceptions/moduledependencies.png[width=200,link=jigsaw-examples/example_exceptions/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_exceptions/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_exceptions/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_exceptions/m4/[code] | xref:jigsaw-examples/example_interface-callback/README.adoc[interface-callback] | What happens, when outside the module a callback implementation is called which package is not exported? Relates to all other examples in this section. | image:jigsaw-examples/example_interface-callback/moduledependencies.png[width=200,link=jigsaw-examples/example_interface-callback/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_interface-callback/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_interface-callback/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_interface-callback/m4/[code] 4+| *Examples on specificing add options* @@ -533,21 +560,21 @@ Relates to all other examples in this section. Relates to all other examples in this section. | image:jigsaw-examples/example_addExports_manifest/moduledependencies.png[width=200,link=jigsaw-examples/example_addExports_manifest/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_addExports_manifest/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_addExports_manifest/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_addExports_manifest/m4/[code] | xref:jigsaw-examples/example_addReads_addExports/README.adoc[addReads_addExports] | How can we use --add-reads and --add-exports for Javac compiler and Java launcher Relates to all other examples in this section. | image:jigsaw-examples/example_addReads_addExports/moduledependencies.png[width=200,link=jigsaw-examples/example_addReads_addExports/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_addReads_addExports/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_addReads_addExports/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_addReads_addExports/m4/[code] | xref:jigsaw-examples/example_addReads_addExports_reflection/README.adoc[addReads_addExports_reflection] | How can we use --add-reads and --add-exports for reflection calls? Relates to all other examples in this section. | image:jigsaw-examples/example_addReads_addExports_reflection/moduledependencies.png[width=200,link=jigsaw-examples/example_addReads_addExports_reflection/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_addReads_addExports_reflection/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_addReads_addExports_reflection/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_addReads_addExports_reflection/m4/[code] 4+| *Examples on automatic modules* @@ -556,14 +583,14 @@ Relates to all other examples in this section. Related example: xref:jigsaw-examples/example_splitpackage_automatic-modules/README.adoc[splitpackage_automatic-modules] | image:jigsaw-examples/example_automatic-module-logging/moduledependencies.png[width=200,link=jigsaw-examples/example_automatic-module-logging/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_automatic-module-logging/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_automatic-module-logging/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_automatic-module-logging/m4/[code] 4+| *Examples on restricting the access to resources in other modules* | xref:jigsaw-examples/example_resources/README.adoc[resources] | Which resources in modules are accessible, which are not? | image:jigsaw-examples/example_resources/moduledependencies.png[width=200,link=jigsaw-examples/example_resources/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_resources/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_resources/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_resources/m4/[code] 4+| *Examples on the split package problem* @@ -572,14 +599,14 @@ Related example: xref:jigsaw-examples/example_splitpackage_automatic-modules/REA Relates to all other examples in this section. | image:jigsaw-examples/example_splitpackage/moduledependencies.png[width=200,link=jigsaw-examples/example_splitpackage/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_splitpackage/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_splitpackage/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_splitpackage/m4/[code] | xref:jigsaw-examples/example_splitpackage_automatic-modules/README.adoc[splitpackage_automatic-modules] | What happens when one Automatic Module automatically reads all other Automatic Modules on the module path and hence creates an unwanted split package problem? Related examples: xref:jigsaw-examples/example_automatic-module-logging/README.adoc[automatic-module-logging] and all other examples in this section. | image:jigsaw-examples/example_splitpackage_automatic-modules/moduledependencies.png[width=200,link=jigsaw-examples/example_splitpackage_automatic-modules/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_splitpackage_automatic-modules/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_splitpackage_automatic-modules/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_splitpackage_automatic-modules/m4/[code] 4+| *Examples on resolution of modules, layers and visibility of modules between layers* @@ -588,42 +615,42 @@ Related examples: xref:jigsaw-examples/example_automatic-module-logging/README.a Relates to all other examples in this section. | -| xref:jigsaw-examples/example_jerrymouse/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_jerrymouse/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_jerrymouse/m4/[code] | xref:jigsaw-examples/example_resolved-modules/README.adoc[resolved-modules] | Which modules are resolved? Usage of jlink Relates to all other examples in this section. | image:jigsaw-examples/example_resolved-modules/moduledependencies.png[width=200,link=jigsaw-examples/example_resolved-modules/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_resolved-modules/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_resolved-modules/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_resolved-modules/m4/[code] | xref:jigsaw-examples/example_layer-hierarchy/README.adoc[layer-hierarchy] | How can one create a hierarchy of layers automatically and add modules (naming conventions)? Relates to all other examples in this section. | image:jigsaw-examples/example_layer-hierarchy/layer-hierarchy.drawio.svg[width=200,link=jigsaw-examples/example_layer-hierarchy/layer-hierarchy.drawio.svg] -| xref:jigsaw-examples/example_layer-hierarchy/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_layer-hierarchy/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_layer-hierarchy/m4/[code] | xref:jigsaw-examples/example_layer-modules-all-in-boot-layer/README.adoc[layer-modules-all-in-boot-layer] | How does the boot layer look like containing a bunch of modules? Relates to all other examples in this section. | image:jigsaw-examples/example_layer-modules-all-in-boot-layer/moduledependencies.png[width=200,link=jigsaw-examples/example_layer-modules-all-in-boot-layer/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_layer-modules-all-in-boot-layer/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_layer-modules-all-in-boot-layer/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_layer-modules-all-in-boot-layer/m4/[code] | xref:jigsaw-examples/example_layer-modules-grouped-in-hierarchy/README.adoc[layer-modules-grouped-in-hierarchy] | How does a small hiearchy of layers look like when one explicitely distributes a bunch of modules to these layers? Relates to all other examples in this section. | image:jigsaw-examples/example_layer-modules-grouped-in-hierarchy/moduledependencies.png[width=200,link=jigsaw-examples/example_layer-modules-grouped-in-hierarchy/moduledependencies.png] -| xref:jigsaw-examples/example_layer-modules-grouped-in-hierarchy/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_layer-modules-grouped-in-hierarchy/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_layer-modules-grouped-in-hierarchy/m4/[code] | xref:jigsaw-examples/example_layer-modules-module-resolution/README.adoc[layer-modules-module-resolution] | How are different versions of a module resolved depending on the setup of the layer? Relates to all other examples in this section. | -| xref:jigsaw-examples/example_layer-modules-module-resolution/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_layer-modules-module-resolution/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_layer-modules-module-resolution/m4/[code] 4+| *Examples on testing* @@ -632,7 +659,7 @@ Relates to all other examples in this section. Relates to all other examples in this section. | image:jigsaw-examples/example_test/moduledependencies.png[width=200,link=jigsaw-examples/example_test/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_test/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_test/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_test/m4/[code] | xref:jigsaw-examples/example_maven-test-blackbox/README.adoc[maven-test-blackbox] | How can one achieve blackbox testing with Maven? @@ -653,14 +680,14 @@ Relates to all other examples in this section. Relates to all other examples in this section. | image:jigsaw-examples/example_patch/moduledependencies.png[width=200,link=jigsaw-examples/example_patch/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_patch/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_patch/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_patch/m4/[code] 4+| *Examples on Main classes* | xref:jigsaw-examples/example_hiddenmain/README.adoc[hiddenmain] | Is it possible that one can call a Main class which is in a non-exported package? | image:jigsaw-examples/example_hiddenmain/moduledependencies.png[width=200,link=jigsaw-examples/example_hiddenmain/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_hiddenmain/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_hiddenmain/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_hiddenmain/m4/[code] 4+| *Examples on access from and to the classpath (i.e. the unnamed module)* | xref:jigsaw-examples/example_unnamed-module_access-from-automatic-module/README.adoc[unnamed-module_access-from-automatic-module] @@ -668,35 +695,35 @@ Relates to all other examples in this section. Relates to all other examples in this section. | -| xref:jigsaw-examples/example_unnamed-module_access-from-automatic-module/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_unnamed-module_access-from-automatic-module/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_unnamed-module_access-from-automatic-module/m4/[code] | xref:jigsaw-examples/example_unnamed-module_access-from-explicit-module/README.adoc[unnamed-module_access-from-explicit-module] | Can a Explicit Module access the classpath (i.e. the unnamed module)? Relates to all other examples in this section. | image:jigsaw-examples/example_unnamed-module_access-from-explicit-module/moduledependencies.png[width=200,link=jigsaw-examples/example_unnamed-module_access-from-explicit-module/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_unnamed-module_access-from-explicit-module/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_unnamed-module_access-from-explicit-module/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_unnamed-module_access-from-explicit-module/m4/[code] | xref:jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/README.adoc[unnamed-module_access-from-explicit-module-reflection] | Can a Explicit Module access the classpath (i.e. the unnamed module) via reflection? Relates to all other examples in this section. | image:jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/moduledependencies.png[width=200,link=jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_unnamed-module_access-from-explicit-module-reflection/m4/[code] | xref:jigsaw-examples/example_unnamed-module-reflection-illegal-access/README.adoc[unnamed-module-reflection-illegal-access] | Can the classpath (i.e. the unnamed module) access concealed packages in the JDK and what happens when the JDK "kill switch" is activated? Relates to all other examples in this section. | image:jigsaw-examples/example_unnamed-module-reflection-illegal-access/moduledependencies.png[width=200,link=jigsaw-examples/example_unnamed-module-reflection-illegal-access/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_unnamed-module-reflection-illegal-access/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_unnamed-module-reflection-illegal-access/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_unnamed-module-reflection-illegal-access/m4/[code] | xref:jigsaw-examples/example_unnamed-module_accessing-module-path/README.adoc[unnamed-module_accessing-module-path] | Can the classpath (i.e. the unnamed module) access modules on the module path? Relates to all other examples in this section. | image:jigsaw-examples/example_unnamed-module_accessing-module-path/moduledependencies.png[width=200,link=jigsaw-examples/example_unnamed-module_accessing-module-path/moduledependencies-withlegend.png] -| xref:jigsaw-examples/example_unnamed-module_accessing-module-path/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| xref:jigsaw-examples/example_unnamed-module_accessing-module-path/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] / link:{example-base}/example_unnamed-module_accessing-module-path/m4/[code] 4+| *Examples on build systems* @@ -723,14 +750,14 @@ Relates to all other examples in this section. | xref:jigsaw-examples/example_compile-target-jdk8/README.adoc[compile-target-jdk8] | What happens when one compiles with a modern JDK while targeting Java release 8 for backwards compatibility? | -| xref:jigsaw-examples/example_compile-target-jdk8/README.adoc#sec:maven-4-migration[icon:exclamation-triangle[role=yellow]] +| N/A 4+| *Examples on non-Jigsaw topics* | xref:jigsaw-examples/example_version/README.adoc[version] | How does the new Java 9 version string (cf JEP 223) look like? | -| xref:jigsaw-examples/example_version/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] +| xref:jigsaw-examples/example_version/README.adoc#sec:maven-4-migration[icon:check-circle[role=green]] / link:{example-base}/example_version/m4/[code] |=== diff --git a/jigsaw-examples/example_addExports_manifest/README.adoc b/jigsaw-examples/example_addExports_manifest/README.adoc index 440bc5a7..798f4447 100644 --- a/jigsaw-examples/example_addExports_manifest/README.adoc +++ b/jigsaw-examples/example_addExports_manifest/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_addExports_manifest/m4/.gitignore b/jigsaw-examples/example_addExports_manifest/m4/.gitignore index 39cc9516..6f7cb630 100644 --- a/jigsaw-examples/example_addExports_manifest/m4/.gitignore +++ b/jigsaw-examples/example_addExports_manifest/m4/.gitignore @@ -1,2 +1 @@ -mlib/ run-result/ diff --git a/jigsaw-examples/example_addExports_manifest/m4/clean.sh b/jigsaw-examples/example_addExports_manifest/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_addExports_manifest/m4/clean.sh +++ b/jigsaw-examples/example_addExports_manifest/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_addExports_manifest/m4/compile.sh b/jigsaw-examples/example_addExports_manifest/m4/compile.sh index cc480531..8b068d83 100755 --- a/jigsaw-examples/example_addExports_manifest/m4/compile.sh +++ b/jigsaw-examples/example_addExports_manifest/m4/compile.sh @@ -20,30 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, targets Java 11 via maven.compiler.source/target)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - # Check if there's a custom MANIFEST.MF file for this module (via source symlink structure) - if [ -f "../../src/${MODDIR}/main/java/META-INF/MANIFEST.MF" ]; then - echo "jar $JAR_OPTIONS --create --manifest=../../src/${MODDIR}/main/java/META-INF/MANIFEST.MF --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --manifest="../../src/${MODDIR}/main/java/META-INF/MANIFEST.MF" --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 - else - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 - fi -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_addExports_manifest/m4/pom.xml b/jigsaw-examples/example_addExports_manifest/m4/pom.xml index eeb35259..7d7ebe77 100644 --- a/jigsaw-examples/example_addExports_manifest/m4/pom.xml +++ b/jigsaw-examples/example_addExports_manifest/m4/pom.xml @@ -19,11 +19,9 @@ moda - src/moda/main/java modmain - src/modmain/main/java @@ -45,6 +43,44 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + moda + package + + jar + + + ${project.build.outputDirectory}/moda + moda + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + src/modmain/main/java/META-INF/MANIFEST.MF + + + + + diff --git a/jigsaw-examples/example_addExports_manifest/m4/run.sh b/jigsaw-examples/example_addExports_manifest/m4/run.sh index 32fa4e24..7698bdbb 100755 --- a/jigsaw-examples/example_addExports_manifest/m4/run.sh +++ b/jigsaw-examples/example_addExports_manifest/m4/run.sh @@ -23,11 +23,11 @@ mkdir -p run-result "${JAVA11_HOME}/bin/java" ${JAVA_OPTIONS} \ --add-exports java.base/jdk.internal.misc=modmain \ --add-exports moda/pkgainternal=modmain \ - --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho + --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho # Second run: Allow access to moda with using the "Add-Exports" entry from MANIFEST.MF # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting "${JAVA11_HOME}/bin/java" ${JAVA_OPTIONS} \ --add-modules moda \ - --module-path mlib \ - -jar mlib/modmain.jar 2>&1 | normalize | tee -a run-result/run.txt | myecho + --module-path target \ + -jar target/example_addExports_manifest-m4-1.0-SNAPSHOT-modmain.jar 2>&1 | normalize | tee -a run-result/run.txt | myecho diff --git a/jigsaw-examples/example_addReads_addExports/README.adoc b/jigsaw-examples/example_addReads_addExports/README.adoc index 53b26cb8..fc661bf8 100644 --- a/jigsaw-examples/example_addReads_addExports/README.adoc +++ b/jigsaw-examples/example_addReads_addExports/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_addReads_addExports/m4/.gitignore b/jigsaw-examples/example_addReads_addExports/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_addReads_addExports/m4/.gitignore +++ b/jigsaw-examples/example_addReads_addExports/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_addReads_addExports/m4/clean.sh b/jigsaw-examples/example_addReads_addExports/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_addReads_addExports/m4/clean.sh +++ b/jigsaw-examples/example_addReads_addExports/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_addReads_addExports/m4/compile.sh b/jigsaw-examples/example_addReads_addExports/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_addReads_addExports/m4/compile.sh +++ b/jigsaw-examples/example_addReads_addExports/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_addReads_addExports/m4/pom.xml b/jigsaw-examples/example_addReads_addExports/m4/pom.xml index ba3f0258..3354f696 100644 --- a/jigsaw-examples/example_addReads_addExports/m4/pom.xml +++ b/jigsaw-examples/example_addReads_addExports/m4/pom.xml @@ -18,15 +18,12 @@ modb - src/modb/main/java modc - src/modc/main/java modmain - src/modmain/main/java @@ -49,6 +46,52 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modc + package + + jar + + + ${project.build.outputDirectory}/modc + modc + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_addReads_addExports/m4/run.sh b/jigsaw-examples/example_addReads_addExports/m4/run.sh index 70a05838..ee4db79e 100755 --- a/jigsaw-examples/example_addReads_addExports/m4/run.sh +++ b/jigsaw-examples/example_addReads_addExports/m4/run.sh @@ -14,7 +14,7 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib \ +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target \ --add-modules modb,modc \ --add-reads modmain=modb \ --add-reads modb=modc \ diff --git a/jigsaw-examples/example_addReads_addExports_reflection/README.adoc b/jigsaw-examples/example_addReads_addExports_reflection/README.adoc index adc85751..32d2bdde 100644 --- a/jigsaw-examples/example_addReads_addExports_reflection/README.adoc +++ b/jigsaw-examples/example_addReads_addExports_reflection/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_addReads_addExports_reflection/m4/.gitignore b/jigsaw-examples/example_addReads_addExports_reflection/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_addReads_addExports_reflection/m4/.gitignore +++ b/jigsaw-examples/example_addReads_addExports_reflection/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_addReads_addExports_reflection/m4/clean.sh b/jigsaw-examples/example_addReads_addExports_reflection/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_addReads_addExports_reflection/m4/clean.sh +++ b/jigsaw-examples/example_addReads_addExports_reflection/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_addReads_addExports_reflection/m4/compile.sh b/jigsaw-examples/example_addReads_addExports_reflection/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_addReads_addExports_reflection/m4/compile.sh +++ b/jigsaw-examples/example_addReads_addExports_reflection/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_addReads_addExports_reflection/m4/pom.xml b/jigsaw-examples/example_addReads_addExports_reflection/m4/pom.xml index f094ffeb..2ca8cfd0 100644 --- a/jigsaw-examples/example_addReads_addExports_reflection/m4/pom.xml +++ b/jigsaw-examples/example_addReads_addExports_reflection/m4/pom.xml @@ -18,11 +18,9 @@ modb - src/modb/main/java modmain - src/modmain/main/java @@ -41,6 +39,41 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_addReads_addExports_reflection/m4/run.sh b/jigsaw-examples/example_addReads_addExports_reflection/m4/run.sh index f2324c95..ab44bca6 100755 --- a/jigsaw-examples/example_addReads_addExports_reflection/m4/run.sh +++ b/jigsaw-examples/example_addReads_addExports_reflection/m4/run.sh @@ -16,7 +16,7 @@ mkdir -p run-result # note: not done here (but via api in modmain, see Main.java#26) as a replacement for --add-reads modmain=modb # note: not done here (but via api in modmain, see Main.java#30) as a replacement for --add-exports modb/pkgbinternal=modmain # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib \ +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target \ --add-modules modb \ --add-exports modb/pkgb=modmain \ --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_agent/README.adoc b/jigsaw-examples/example_agent/README.adoc index 8e23a3cd..0533410b 100644 --- a/jigsaw-examples/example_agent/README.adoc +++ b/jigsaw-examples/example_agent/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_annotations/README.adoc b/jigsaw-examples/example_annotations/README.adoc index c8f5eba4..ddcfbaa3 100644 --- a/jigsaw-examples/example_annotations/README.adoc +++ b/jigsaw-examples/example_annotations/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_annotations/m4/.gitignore b/jigsaw-examples/example_annotations/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_annotations/m4/.gitignore +++ b/jigsaw-examples/example_annotations/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_annotations/m4/clean.sh b/jigsaw-examples/example_annotations/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_annotations/m4/clean.sh +++ b/jigsaw-examples/example_annotations/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_annotations/m4/compile.sh b/jigsaw-examples/example_annotations/m4/compile.sh index f872668c..37682871 100755 --- a/jigsaw-examples/example_annotations/m4/compile.sh +++ b/jigsaw-examples/example_annotations/m4/compile.sh @@ -20,23 +20,10 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib - echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package diff --git a/jigsaw-examples/example_annotations/m4/pom.xml b/jigsaw-examples/example_annotations/m4/pom.xml index 8e7f9f1a..e93ccb15 100644 --- a/jigsaw-examples/example_annotations/m4/pom.xml +++ b/jigsaw-examples/example_annotations/m4/pom.xml @@ -18,15 +18,12 @@ mod.annotations - src/mod.annotations/main/java modb - src/modb/main/java modmain - src/modmain/main/java @@ -36,6 +33,52 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + mod.annotations + package + + jar + + + ${project.build.outputDirectory}/mod.annotations + mod.annotations + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_annotations/m4/run.sh b/jigsaw-examples/example_annotations/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_annotations/m4/run.sh +++ b/jigsaw-examples/example_annotations/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_automatic-module-logging/README.adoc b/jigsaw-examples/example_automatic-module-logging/README.adoc index f1d9b6f8..1d494c17 100644 --- a/jigsaw-examples/example_automatic-module-logging/README.adoc +++ b/jigsaw-examples/example_automatic-module-logging/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_automatic-module-logging/m4/.gitignore b/jigsaw-examples/example_automatic-module-logging/m4/.gitignore index 1c45f36b..4b4fce97 100644 --- a/jigsaw-examples/example_automatic-module-logging/m4/.gitignore +++ b/jigsaw-examples/example_automatic-module-logging/m4/.gitignore @@ -1,4 +1,3 @@ target/ -mlib/ run-result/ amlib-api/ diff --git a/jigsaw-examples/example_automatic-module-logging/m4/clean.sh b/jigsaw-examples/example_automatic-module-logging/m4/clean.sh index f492f39b..31759580 100755 --- a/jigsaw-examples/example_automatic-module-logging/m4/clean.sh +++ b/jigsaw-examples/example_automatic-module-logging/m4/clean.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf amlib-api rm -rf run-result diff --git a/jigsaw-examples/example_automatic-module-logging/m4/compile.sh b/jigsaw-examples/example_automatic-module-logging/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_automatic-module-logging/m4/compile.sh +++ b/jigsaw-examples/example_automatic-module-logging/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_automatic-module-logging/m4/pom.xml b/jigsaw-examples/example_automatic-module-logging/m4/pom.xml index d9c0b2d7..e1557968 100644 --- a/jigsaw-examples/example_automatic-module-logging/m4/pom.xml +++ b/jigsaw-examples/example_automatic-module-logging/m4/pom.xml @@ -26,7 +26,6 @@ modmain - src/modmain/main/java @@ -62,6 +61,30 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_automatic-module-logging/m4/run.sh b/jigsaw-examples/example_automatic-module-logging/m4/run.sh index 855c7d71..a7493dcf 100755 --- a/jigsaw-examples/example_automatic-module-logging/m4/run.sh +++ b/jigsaw-examples/example_automatic-module-logging/m4/run.sh @@ -28,7 +28,7 @@ echo "Using slf4j.jdk14 as implementation for slf4j, see also #VersionsInModuleN # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \ - --module-path mlib"${PATH_SEPARATOR}"amlib-api"${PATH_SEPARATOR}"../amlib-jdk14 \ + --module-path target"${PATH_SEPARATOR}"amlib-api"${PATH_SEPARATOR}"../amlib-jdk14 \ --add-modules slf4j.jdk14 \ --module modmain/pkgmain.Main 2>&1 | normalize | normalize_extra | tee -a run-result/run.txt | myecho @@ -38,7 +38,7 @@ echo "Using slf4j.simple as implementation for slf4j" # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \ - --module-path mlib"${PATH_SEPARATOR}"amlib-api"${PATH_SEPARATOR}"../amlib-simple \ + --module-path target"${PATH_SEPARATOR}"amlib-api"${PATH_SEPARATOR}"../amlib-simple \ --add-modules slf4j.simple \ --module modmain/pkgmain.Main 2>&1 | normalize | normalize_extra | tee -a run-result/run.txt | myecho @@ -47,7 +47,7 @@ echo echo "Exception expected: java.lang.module.ResolutionException: Modules slf4j.jdk14 and slf4j.simple export package org.slf4j.impl to module slf4j.api" # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting if "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \ - --module-path mlib"${PATH_SEPARATOR}"amlib-api"${PATH_SEPARATOR}"../amlib-simple"${PATH_SEPARATOR}"../amlib-jdk14 \ + --module-path target"${PATH_SEPARATOR}"amlib-api"${PATH_SEPARATOR}"../amlib-simple"${PATH_SEPARATOR}"../amlib-jdk14 \ --add-modules slf4j.simple\,slf4j.jdk14 \ --module modmain/pkgmain.Main 2>&1 | normalize | normalize_extra | sed -e 's,^java.lang.module.ResolutionException:.*,java.lang.module.ResolutionException: ...,g' | tee -a run-result/run.txt | myecho; then echo "An exception should occur here!" >&2 diff --git a/jigsaw-examples/example_compile-target-jdk8/README.adoc b/jigsaw-examples/example_compile-target-jdk8/README.adoc index dceca4eb..e784d224 100644 --- a/jigsaw-examples/example_compile-target-jdk8/README.adoc +++ b/jigsaw-examples/example_compile-target-jdk8/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -58,7 +58,7 @@ include::run-result/run.txt[] [[sec:maven-4-migration]] === Maven 4 Migration -This example does not include a Maven 4 migration variant (`m4/` directory) because it is primarily about demonstrating compatibility with older JDK 8 code, not about the Java Platform Module System (JPMS). +This example does not include a Maven 4 migration variant (`m4/` directory) because it is primarily about demonstrating compatibility with older JDK 8 code, not about Java Modules. The example focuses on cross-compilation targeting JDK 8, which is independent of Maven version. -Since the migration to Maven 4 in this repository focuses on JPMS-related module system features, and this example doesn't rely on JPMS, there is no need for a separate Maven 4 migration demonstration here. +Since the migration to Maven 4 in this repository focuses on Java Modules-related features, and this example doesn't rely on Java Modules, there is no need for a separate Maven 4 migration demonstration here. diff --git a/jigsaw-examples/example_derived_private-package-protected/README.adoc b/jigsaw-examples/example_derived_private-package-protected/README.adoc index 88c3b8b6..6ebdec15 100644 --- a/jigsaw-examples/example_derived_private-package-protected/README.adoc +++ b/jigsaw-examples/example_derived_private-package-protected/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_derived_private-package-protected/m4/.gitignore b/jigsaw-examples/example_derived_private-package-protected/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_derived_private-package-protected/m4/.gitignore +++ b/jigsaw-examples/example_derived_private-package-protected/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_derived_private-package-protected/m4/clean.sh b/jigsaw-examples/example_derived_private-package-protected/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_derived_private-package-protected/m4/clean.sh +++ b/jigsaw-examples/example_derived_private-package-protected/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_derived_private-package-protected/m4/compile.sh b/jigsaw-examples/example_derived_private-package-protected/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_derived_private-package-protected/m4/compile.sh +++ b/jigsaw-examples/example_derived_private-package-protected/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_derived_private-package-protected/m4/pom.xml b/jigsaw-examples/example_derived_private-package-protected/m4/pom.xml index 123940a0..41cfd0ea 100644 --- a/jigsaw-examples/example_derived_private-package-protected/m4/pom.xml +++ b/jigsaw-examples/example_derived_private-package-protected/m4/pom.xml @@ -18,11 +18,9 @@ modb - src/modb/main/java modmain - src/modmain/main/java @@ -32,6 +30,41 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_derived_private-package-protected/m4/run.sh b/jigsaw-examples/example_derived_private-package-protected/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_derived_private-package-protected/m4/run.sh +++ b/jigsaw-examples/example_derived_private-package-protected/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_exceptions/README.adoc b/jigsaw-examples/example_exceptions/README.adoc index 91a13b9c..ca828503 100644 --- a/jigsaw-examples/example_exceptions/README.adoc +++ b/jigsaw-examples/example_exceptions/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_exceptions/m4/.gitignore b/jigsaw-examples/example_exceptions/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_exceptions/m4/.gitignore +++ b/jigsaw-examples/example_exceptions/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_exceptions/m4/clean.sh b/jigsaw-examples/example_exceptions/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_exceptions/m4/clean.sh +++ b/jigsaw-examples/example_exceptions/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_exceptions/m4/compile.sh b/jigsaw-examples/example_exceptions/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_exceptions/m4/compile.sh +++ b/jigsaw-examples/example_exceptions/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_exceptions/m4/pom.xml b/jigsaw-examples/example_exceptions/m4/pom.xml index 59bce923..cdf26390 100644 --- a/jigsaw-examples/example_exceptions/m4/pom.xml +++ b/jigsaw-examples/example_exceptions/m4/pom.xml @@ -18,11 +18,9 @@ modb - src/modb/main/java modmain - src/modmain/main/java @@ -32,6 +30,41 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_exceptions/m4/run.sh b/jigsaw-examples/example_exceptions/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_exceptions/m4/run.sh +++ b/jigsaw-examples/example_exceptions/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_gradle-project/README.adoc b/jigsaw-examples/example_gradle-project/README.adoc index 037094bc..aa8559fa 100644 --- a/jigsaw-examples/example_gradle-project/README.adoc +++ b/jigsaw-examples/example_gradle-project/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_hiddenmain/README.adoc b/jigsaw-examples/example_hiddenmain/README.adoc index 3cf5d574..b388232a 100644 --- a/jigsaw-examples/example_hiddenmain/README.adoc +++ b/jigsaw-examples/example_hiddenmain/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_hiddenmain/m4/.gitignore b/jigsaw-examples/example_hiddenmain/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_hiddenmain/m4/.gitignore +++ b/jigsaw-examples/example_hiddenmain/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_hiddenmain/m4/clean.sh b/jigsaw-examples/example_hiddenmain/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_hiddenmain/m4/clean.sh +++ b/jigsaw-examples/example_hiddenmain/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_hiddenmain/m4/compile.sh b/jigsaw-examples/example_hiddenmain/m4/compile.sh index f872668c..37682871 100755 --- a/jigsaw-examples/example_hiddenmain/m4/compile.sh +++ b/jigsaw-examples/example_hiddenmain/m4/compile.sh @@ -20,23 +20,10 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib - echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package diff --git a/jigsaw-examples/example_hiddenmain/m4/pom.xml b/jigsaw-examples/example_hiddenmain/m4/pom.xml index d21ab1e1..d9b9f804 100644 --- a/jigsaw-examples/example_hiddenmain/m4/pom.xml +++ b/jigsaw-examples/example_hiddenmain/m4/pom.xml @@ -18,7 +18,6 @@ modmain - src/modmain/main/java @@ -28,6 +27,30 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_hiddenmain/m4/run.sh b/jigsaw-examples/example_hiddenmain/m4/run.sh index 8eeb5611..b76921b2 100755 --- a/jigsaw-examples/example_hiddenmain/m4/run.sh +++ b/jigsaw-examples/example_hiddenmain/m4/run.sh @@ -14,8 +14,8 @@ mkdir -p run-result # Run the first Java command, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho # Run the second Java command, append output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmainhidden.HiddenMain 2>&1 | normalize | tee -a run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmainhidden.HiddenMain 2>&1 | normalize | tee -a run-result/run.txt | myecho diff --git a/jigsaw-examples/example_interface-callback/README.adoc b/jigsaw-examples/example_interface-callback/README.adoc index 13522c7c..603eda98 100644 --- a/jigsaw-examples/example_interface-callback/README.adoc +++ b/jigsaw-examples/example_interface-callback/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_interface-callback/m4/.gitignore b/jigsaw-examples/example_interface-callback/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_interface-callback/m4/.gitignore +++ b/jigsaw-examples/example_interface-callback/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_interface-callback/m4/clean.sh b/jigsaw-examples/example_interface-callback/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_interface-callback/m4/clean.sh +++ b/jigsaw-examples/example_interface-callback/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_interface-callback/m4/compile.sh b/jigsaw-examples/example_interface-callback/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_interface-callback/m4/compile.sh +++ b/jigsaw-examples/example_interface-callback/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_interface-callback/m4/pom.xml b/jigsaw-examples/example_interface-callback/m4/pom.xml index fbc067a5..568dc640 100644 --- a/jigsaw-examples/example_interface-callback/m4/pom.xml +++ b/jigsaw-examples/example_interface-callback/m4/pom.xml @@ -18,15 +18,12 @@ modcallbackhandler - src/modcallbackhandler/main/java modcallee - src/modcallee/main/java modmain - src/modmain/main/java @@ -36,6 +33,52 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modcallbackhandler + package + + jar + + + ${project.build.outputDirectory}/modcallbackhandler + modcallbackhandler + + + + modcallee + package + + jar + + + ${project.build.outputDirectory}/modcallee + modcallee + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_interface-callback/m4/run.sh b/jigsaw-examples/example_interface-callback/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_interface-callback/m4/run.sh +++ b/jigsaw-examples/example_interface-callback/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_jerrymouse/README.adoc b/jigsaw-examples/example_jerrymouse/README.adoc index 78adf257..447ca4ff 100644 --- a/jigsaw-examples/example_jerrymouse/README.adoc +++ b/jigsaw-examples/example_jerrymouse/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -121,7 +121,7 @@ Created `m4/apps_copyallexamples2appdir.sh` script. + * Copies Maven 4 versions of example applications from whitelisted examples * Builds M4 versions of dependencies if they don't exist yet -* Sources from `../example_*/m4/mlib/` instead of `../example_*/mlib/` +* Sources from `../example_*/m4/target/` (JARs created by maven-jar-plugin) * Creates `app.json` descriptors for each application Runtime Configuration:: diff --git a/jigsaw-examples/example_jerrymouse/m4/.gitignore b/jigsaw-examples/example_jerrymouse/m4/.gitignore index 3cd36bb3..d893b34a 100644 --- a/jigsaw-examples/example_jerrymouse/m4/.gitignore +++ b/jigsaw-examples/example_jerrymouse/m4/.gitignore @@ -1,5 +1,4 @@ target/ -mlib/ amlib/ apps/ run-result/ \ No newline at end of file diff --git a/jigsaw-examples/example_jerrymouse/m4/apps_copyallexamples2appdir.sh b/jigsaw-examples/example_jerrymouse/m4/apps_copyallexamples2appdir.sh index b24b2996..de103cbb 100755 --- a/jigsaw-examples/example_jerrymouse/m4/apps_copyallexamples2appdir.sh +++ b/jigsaw-examples/example_jerrymouse/m4/apps_copyallexamples2appdir.sh @@ -3,8 +3,8 @@ set -eu -o pipefail # -# Copy all apps from our app whitelist (Maven 4 versions) -# This is the Maven 4 variant that copies from ../example_*/m4/mlib/ directories +# Copy all apps from our app whitelist (Maven 4 versions - Phase 2) +# This is the Maven 4 variant that copies from ../example_*/m4/target/ directories # # source the list of apps which we want to run in the Jerry Mouse app server @@ -17,14 +17,15 @@ do MODDIR="${dir%*/}" # if the example really is "worth" to be copied, i.e. not empty... - if [ ! -e "../../${MODDIR}/m4/mlib/modmain.jar" ]; then + # Check for JAR files in target/ directory (Phase 2 migration) + if ! compgen -G "../../${MODDIR}/m4/target"/*.jar > /dev/null; then echo "Building Maven 4 version of ${MODDIR}..." (cd "../../${MODDIR}/m4" && ./compile.sh) fi pushd "../../${MODDIR}/m4" > /dev/null 2>&1 echo "###################################################################################################################################" - echo "Copy ${MODDIR}/m4/mlib/*.jar to ${APPSERVER_TARGET}/${MODDIR} ..." + echo "Copy ${MODDIR}/m4/target/*.jar to ${APPSERVER_TARGET}/${MODDIR}/mlib ..." mkdir -p "${APPSERVER_TARGET}"/"${MODDIR}" pushd "${APPSERVER_TARGET}"/"${MODDIR}" > /dev/null 2>&1 @@ -40,7 +41,8 @@ EOFAPPJSON mkdir -p "${APPSERVER_TARGET}"/"${MODDIR}/mlib" popd >/dev/null 2>&1 - pushd mlib > /dev/null 2>&1 + # Copy JARs from target/ directory (Phase 2 migration) + pushd target > /dev/null 2>&1 cp -R ./*.jar "${APPSERVER_TARGET}"/"${MODDIR}/mlib" popd >/dev/null 2>&1 diff --git a/jigsaw-examples/example_jerrymouse/m4/clean.sh b/jigsaw-examples/example_jerrymouse/m4/clean.sh index 756a7e72..fd9dedc5 100755 --- a/jigsaw-examples/example_jerrymouse/m4/clean.sh +++ b/jigsaw-examples/example_jerrymouse/m4/clean.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf amlib rm -rf apps rm -rf run-result diff --git a/jigsaw-examples/example_jerrymouse/m4/compile.sh b/jigsaw-examples/example_jerrymouse/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_jerrymouse/m4/compile.sh +++ b/jigsaw-examples/example_jerrymouse/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_jerrymouse/m4/pom.xml b/jigsaw-examples/example_jerrymouse/m4/pom.xml index b12578f5..e7a2f449 100644 --- a/jigsaw-examples/example_jerrymouse/m4/pom.xml +++ b/jigsaw-examples/example_jerrymouse/m4/pom.xml @@ -26,7 +26,6 @@ modstarter - src/modstarter/main/java @@ -62,6 +61,30 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modstarter + package + + jar + + + ${project.build.outputDirectory}/modstarter + modstarter + + + + diff --git a/jigsaw-examples/example_jerrymouse/m4/run.sh b/jigsaw-examples/example_jerrymouse/m4/run.sh index 459b69f3..dc22011f 100755 --- a/jigsaw-examples/example_jerrymouse/m4/run.sh +++ b/jigsaw-examples/example_jerrymouse/m4/run.sh @@ -17,4 +17,4 @@ mkdir -p run-result # Run the app server (modstarter/pkgstarter.Starter) echo "" # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path "mlib${PATH_SEPARATOR}../amlib" --module modstarter/pkgstarter.Starter . run-result --sync 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path "target${PATH_SEPARATOR}../amlib" --module modstarter/pkgstarter.Starter . run-result --sync 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_layer-hierarchy/README.adoc b/jigsaw-examples/example_layer-hierarchy/README.adoc index fef97b62..40cbcfbb 100644 --- a/jigsaw-examples/example_layer-hierarchy/README.adoc +++ b/jigsaw-examples/example_layer-hierarchy/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -59,9 +59,9 @@ Because of that, _all_ modules already end up in the top layer, because top requ === Understanding the "Reads" Relationship and Split Package Problem -==== JPMS "Reads" Semantics +==== Java Modules "Reads" Semantics -In the Java Platform Module System (JPMS), when module A "reads" module B, it means: +In Java Modules, when module A "reads" module B, it means: * Module A has access to all packages that module B _exports_ * This is established via `requires` declarations in `module-info.java` for explicit modules @@ -86,7 +86,7 @@ In this example: * All modules are on the `--module-path`: `mlib` (application modules) + `amlib` (javax.json) * The compiler sees that `javax.json` reads three modules that all export the same package `pkgx` -* This violates the JPMS rule: "A module cannot read two modules that export the same package" +* This violates the Java Modules rule: "A module cannot read two modules that export the same package" * *Result:* Compilation fails with a split package error *Workaround:* The `mod.x_*` modules must be compiled _separately_ (see compile.sh lines 7-14), so they are never all on the module-path simultaneously when `javax.json` is present. @@ -101,7 +101,7 @@ In this example: [NOTE] ==== -This demonstrates an important aspect of JPMS: _layer isolation at runtime_ provides stronger encapsulation than what's possible at compile time with automatic modules. +This demonstrates an important aspect of Java Modules: _layer isolation at runtime_ provides stronger encapsulation than what's possible at compile time with automatic modules. The compile-time restriction is necessary because automatic modules have automatic reads to all modules, but at runtime, layers provide the isolation needed to avoid conflicts. For more details, see this https://mail.openjdk.java.net/pipermail/jigsaw-dev/2016-September/009290.html[discussion in the jigsaw-dev mailing list]. @@ -145,10 +145,19 @@ The `compile.sh` script manually compiles the three `mod.x_*` modules separately [source,bash] ---- # Compile mod.x_* modules separately (split package problem with automatic module) -for mod in mod.x_bottom mod.x_middle mod.x_top; do - javac -d mods/${mod} --module-path amlib --module-source-path "../src" -m ${mod} - jar --create --file=mlib/${mod}.jar -C mods/${mod}/${mod} . +for modx in mod.x_bottom mod.x_middle mod.x_top; do + javac --release 11 -d target/classes \ + --module-path target:amlib \ + --module-source-path "src/*/main/java" \ + $(find -L src/${modx}/main/java -name "*.java") done + +# Package as JARs in target/ (accessible via mlib symlink) +pushd target/classes > /dev/null +for modx in mod.x_bottom mod.x_middle mod.x_top; do + jar --create --file=../${modx}.jar -C ${modx} . +done +popd > /dev/null ---- *Phase 2 - Maven compilation of remaining modules:* @@ -212,6 +221,29 @@ The automatic module `javax.json` is downloaded via `maven-dependency-plugin` to ---- +*Dynamic module loading via mlib:* + +The Java code in `mod.main/pkgmain/Main.java` uses the `ModuleLayer` API to dynamically load modules at runtime from a hardcoded path: + +[source,java] +---- +layerBuilder.createJigsawLayers(LayerHierarchy.root, LayerHierarchy.root.getLayer(), path + "/mlib"); +---- + +Since Maven (4) creates JARs in the `target/` directory (not `mlib/`), but the shared source code still references `mlib`, the `run.sh` script creates `mlib` using OS-specific approaches: + +Unix/macOS:: Creates symlink `mlib → target` (using `ln -sfn`) +Windows:: Creates directory `mlib/` and copies JARs from `target/` + +The Windows approach avoids `AccessDeniedException` issues when Java's `ModuleLayer` API traverses symlinks. + +[NOTE] +==== +A committed symlink `m4/mlib → target` exists in Git for convenience on Unix systems. +On Windows, this symlink is replaced with a directory and copied JARs at runtime by `run.sh`. +Both approaches redirect the hardcoded `mlib` path to Maven-built JARs without modifying shared source code. +==== + ==== Running the Maven 4 Version [source,bash] diff --git a/jigsaw-examples/example_layer-hierarchy/m4/.gitignore b/jigsaw-examples/example_layer-hierarchy/m4/.gitignore index 2b7e3ffe..9a8f5418 100644 --- a/jigsaw-examples/example_layer-hierarchy/m4/.gitignore +++ b/jigsaw-examples/example_layer-hierarchy/m4/.gitignore @@ -1,7 +1,7 @@ # Maven build output target/ -# Module JARs +# Module library (symlink on Unix, directory on Windows) mlib/ # Automatic module library (copied by maven-dependency-plugin) diff --git a/jigsaw-examples/example_layer-hierarchy/m4/clean.sh b/jigsaw-examples/example_layer-hierarchy/m4/clean.sh index d38543e7..9ae0fc4b 100755 --- a/jigsaw-examples/example_layer-hierarchy/m4/clean.sh +++ b/jigsaw-examples/example_layer-hierarchy/m4/clean.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf amlib +# Only remove mlib on Windows (where it's a directory with copied JARs) +# On Unix, mlib is a committed symlink and should remain +[ "${OS:-$(uname)}" = "Windows_NT" ] && rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_layer-hierarchy/m4/compile.sh b/jigsaw-examples/example_layer-hierarchy/m4/compile.sh index 7e9a82a3..e371f30b 100755 --- a/jigsaw-examples/example_layer-hierarchy/m4/compile.sh +++ b/jigsaw-examples/example_layer-hierarchy/m4/compile.sh @@ -17,9 +17,11 @@ MAVEN_JAVA_HOME="${JAVA17_HOME:-${JAVA_HOME}}" # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib mkdir -p target/classes +# Note: mlib → target symlink is committed to Git +# It will be validated/recreated in run.sh after Maven compilation completes + # Step 1: Use Maven to download dependencies to amlib echo "=== Step 1: Download dependencies with Maven ===" echo @@ -34,30 +36,31 @@ echo echo "=== Step 2: Compile mod.x* modules (separate compilation with javac) ===" for modx in mod.x_bottom mod.x_middle mod.x_top do - echo "javac ${JAVAC_OPTIONS} --release 11 -d target/classes --module-path mlib${PATH_SEPARATOR}amlib --module-source-path \"src/*/main/java\" \$(find -L src/${modx}/main/java -name \"*.java\")" + echo "javac ${JAVAC_OPTIONS} --release 11 -d target/classes --module-path target${PATH_SEPARATOR}amlib --module-source-path \"src/*/main/java\" \$(find -L src/${modx}/main/java -name \"*.java\")" # shellcheck disable=SC2086 # JAVAC_OPTIONS is intentionally unquoted for word splitting # shellcheck disable=SC2046 # Word splitting intentional for multiple Java source files "${JAVA_HOME}/bin/javac" ${JAVAC_OPTIONS} --release 11 -d target/classes \ - --module-path mlib${PATH_SEPARATOR}amlib \ + --module-path target${PATH_SEPARATOR}amlib \ --module-source-path "src/*/main/java" \ $(find -L src/${modx}/main/java -name "*.java") 2>&1 done echo -# Step 3: Compile remaining 12 modules with Maven (pom.xml lists all non-mod.x_* modules) -echo "=== Step 3: Compile remaining 12 modules with Maven compiler plugin ===" -echo "mvn compile" -JAVA_HOME="${MAVEN_JAVA_HOME}" mvn compile +# Step 3: Compile remaining 12 modules with Maven and create JARs +echo "=== Step 3: Compile remaining 12 modules with Maven and create JARs ===" +echo "mvn package" +JAVA_HOME="${MAVEN_JAVA_HOME}" mvn package echo -# Step 4: Create JARs -echo "=== Step 4: Create module JARs ===" +# Step 4: Create JARs in target/ (for modules compiled with javac, Maven-compiled modules already have JARs) +echo "=== Step 4: Create module JARs for javac-compiled modules ===" pushd target/classes > /dev/null 2>&1 -for dir in */; +for modx in mod.x_bottom mod.x_middle mod.x_top do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 + if [ -d "${modx}" ]; then + echo "jar $JAR_OPTIONS --create --file=../${modx}.jar -C ${modx} ." + # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting + "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../${modx}.jar" -C "${modx}" . 2>&1 + fi done popd >/dev/null 2>&1 diff --git a/jigsaw-examples/example_layer-hierarchy/m4/mlib b/jigsaw-examples/example_layer-hierarchy/m4/mlib new file mode 120000 index 00000000..1de56593 --- /dev/null +++ b/jigsaw-examples/example_layer-hierarchy/m4/mlib @@ -0,0 +1 @@ +target \ No newline at end of file diff --git a/jigsaw-examples/example_layer-hierarchy/m4/pom.xml b/jigsaw-examples/example_layer-hierarchy/m4/pom.xml index adb00892..c8d515b6 100644 --- a/jigsaw-examples/example_layer-hierarchy/m4/pom.xml +++ b/jigsaw-examples/example_layer-hierarchy/m4/pom.xml @@ -35,52 +35,40 @@ mod.layer - src/mod.layer/main/java mod.main - src/mod.main/main/java mod.u_bottom_middle_top - src/mod.u_bottom_middle_top/main/java mod.y_bottom - src/mod.y_bottom/main/java mod.y_middle - src/mod.y_middle/main/java mod.y_top - src/mod.y_top/main/java mod.z_bottom - src/mod.z_bottom/main/java mod.z_middle - src/mod.z_middle/main/java mod.z_top - src/mod.z_top/main/java mod.zreverse_bottom - src/mod.zreverse_bottom/main/java mod.zreverse_middle - src/mod.zreverse_middle/main/java mod.zreverse_top - src/mod.zreverse_top/main/java @@ -119,6 +107,151 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + mod.layer + package + + jar + + + ${project.build.outputDirectory}/mod.layer + mod.layer + + + + mod.main + package + + jar + + + ${project.build.outputDirectory}/mod.main + mod.main + + + + mod.u_bottom_middle_top + package + + jar + + + ${project.build.outputDirectory}/mod.u_bottom_middle_top + mod.u_bottom_middle_top + + + + mod.y_bottom + package + + jar + + + ${project.build.outputDirectory}/mod.y_bottom + mod.y_bottom + + + + mod.y_middle + package + + jar + + + ${project.build.outputDirectory}/mod.y_middle + mod.y_middle + + + + mod.y_top + package + + jar + + + ${project.build.outputDirectory}/mod.y_top + mod.y_top + + + + mod.z_bottom + package + + jar + + + ${project.build.outputDirectory}/mod.z_bottom + mod.z_bottom + + + + mod.z_middle + package + + jar + + + ${project.build.outputDirectory}/mod.z_middle + mod.z_middle + + + + mod.z_top + package + + jar + + + ${project.build.outputDirectory}/mod.z_top + mod.z_top + + + + mod.zreverse_bottom + package + + jar + + + ${project.build.outputDirectory}/mod.zreverse_bottom + mod.zreverse_bottom + + + + mod.zreverse_middle + package + + jar + + + ${project.build.outputDirectory}/mod.zreverse_middle + mod.zreverse_middle + + + + mod.zreverse_top + package + + jar + + + ${project.build.outputDirectory}/mod.zreverse_top + mod.zreverse_top + + + + diff --git a/jigsaw-examples/example_layer-hierarchy/m4/run.sh b/jigsaw-examples/example_layer-hierarchy/m4/run.sh index aff9a42f..4abd8a46 100755 --- a/jigsaw-examples/example_layer-hierarchy/m4/run.sh +++ b/jigsaw-examples/example_layer-hierarchy/m4/run.sh @@ -13,6 +13,22 @@ fi # Create run-result directory if it doesn't exist mkdir -p run-result +# Setup mlib for module-path access +# Windows: Copy JARs to mlib/ directory (symlinks cause AccessDeniedException) +# Unix: Use symlink to target/ +if [ "${OS:-$(uname)}" = "Windows_NT" ]; then + # Windows: Ensure mlib is a directory, copy JARs + echo "We are on Windows, copying JARs to mlib/" + rm -rf mlib + mkdir -p mlib + cp -p target/*.jar mlib/ + ls -l mlib/ +else + # Unix: Ensure mlib is a symlink to target + echo "We are on Unix, using JARs from mlib/ as symlink" + test -h mlib || ln -sfn target mlib +fi + echo "Using Java version:" "${JAVA11_HOME}/bin/java" -version echo @@ -20,4 +36,4 @@ echo # Run the Java code, save output to run-result/run.txt, and display with highlighting # The '.' argument specifies the JSON file (layers_triple_hierarchy.json) location # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA11_HOME}/bin/java" ${JAVA_OPTIONS} --module-path "mlib${PATH_SEPARATOR}amlib" --module mod.main/pkgmain.Main . 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA11_HOME}/bin/java" ${JAVA_OPTIONS} --module-path "target${PATH_SEPARATOR}amlib" --module mod.main/pkgmain.Main . 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_layer-modules-all-in-boot-layer/README.adoc b/jigsaw-examples/example_layer-modules-all-in-boot-layer/README.adoc index 2432ab3e..44806ea0 100644 --- a/jigsaw-examples/example_layer-modules-all-in-boot-layer/README.adoc +++ b/jigsaw-examples/example_layer-modules-all-in-boot-layer/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/clean.sh b/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/clean.sh index d0b6b774..964885ee 100755 --- a/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/clean.sh +++ b/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/clean.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf amlib1 rm -rf classes rm -rf run-result diff --git a/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/compile.sh b/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/compile.sh index 6667c4ff..95e283e5 100755 --- a/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/compile.sh +++ b/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/compile.sh @@ -20,7 +20,6 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib mkdir -p amlib1 mkdir -p classes @@ -56,17 +55,7 @@ echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile +mvn clean package -# Create JARs for explicit modules -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 diff --git a/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/pom.xml b/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/pom.xml index 4c401596..8316aba6 100644 --- a/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/pom.xml +++ b/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/pom.xml @@ -19,19 +19,15 @@ modbar - src/modbar/main/java modcommon - src/modcommon/main/java modfoo - src/modfoo/main/java modmain - src/modmain/main/java @@ -47,6 +43,63 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modbar + package + + jar + + + ${project.build.outputDirectory}/modbar + modbar + + + + modcommon + package + + jar + + + ${project.build.outputDirectory}/modcommon + modcommon + + + + modfoo + package + + jar + + + ${project.build.outputDirectory}/modfoo + modfoo + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/run.sh b/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/run.sh index db3d562d..4483dc8e 100755 --- a/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/run.sh +++ b/jigsaw-examples/example_layer-modules-all-in-boot-layer/m4/run.sh @@ -28,7 +28,7 @@ mkdir -p run-result # --add-modules ensures modbar and modfoo are resolved (otherwise they'd be unused) # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \ - --module-path mlib"${PATH_SEPARATOR}"amlib1 \ + --module-path target"${PATH_SEPARATOR}"amlib1 \ --add-modules modbar,modfoo \ --module modmain/pkgmain.Main . \ 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/README.adoc b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/README.adoc index 8bb1faa7..87f6b95e 100644 --- a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/README.adoc +++ b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -144,3 +144,37 @@ This hybrid approach is necessary because: * Split packages between automatic modules prevent compiling all modules together * Each module requiring an automatic module must be compiled separately with only the needed automatic module on path * This example demonstrates module layers where different modules use different automatic module versions + +=== Module-Path Access via mlib for Dynamic Module Loading + +The Java code in `modmain/pkgmain/Main.java` uses the `ModuleLayer` API to dynamically load modules at runtime from hardcoded paths: + +[source,java] +---- +// Dynamically creates layers and loads modules from ./foomlib and ./barmlib +Module fooModule = fooLayer.findModule("modfoo").get(); +Module barModule = barLayer.findModule("modbar").get(); +---- + +Maven (4) creates JARs in the `target/` directory with classifier-based names: + +[source] +---- +target/example_layer-modules-grouped-in-hierarchy-m4-1.0-SNAPSHOT-modcommon.jar +target/example_layer-modules-grouped-in-hierarchy-m4-1.0-SNAPSHOT-modmain.jar +... +---- + +To maintain compatibility with the shared Java source code that references `mlib`, the `run.sh` script creates `mlib` using OS-specific approaches: + +Unix/macOS:: Creates symlink `mlib → target` (using `ln -sfn`) +Windows:: Creates directory `mlib/` and copies JARs from `target/` + +The Windows approach avoids `AccessDeniedException` issues when Java's `ModuleLayer` API traverses symlinks. + +[NOTE] +==== +A committed symlink `m4/mlib → target` exists in Git for convenience on Unix systems. +On Windows, this symlink is replaced with a directory and copied JARs at runtime by `run.sh`. +Both approaches redirect the hardcoded `mlib` path to Maven-built JARs without modifying shared source code. +==== diff --git a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/clean.sh b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/clean.sh index 4936f184..c4908846 100755 --- a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/clean.sh +++ b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/clean.sh @@ -1,8 +1,10 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf amlib1 rm -rf amlib2 rm -rf classes rm -rf mods +# Only remove mlib on Windows (where it's a directory with copied JARs) +# On Unix, mlib is a committed symlink and should remain +[ "${OS:-$(uname)}" = "Windows_NT" ] && rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/compile.sh b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/compile.sh index 0341b157..c8b99f30 100755 --- a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/compile.sh +++ b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/compile.sh @@ -29,7 +29,9 @@ export PATH="${M4_HOME}/bin:${PATH}" mkdir -p amlib1 mkdir -p amlib2 mkdir -p classes -mkdir -p mlib + +# Note: mlib → target symlink is committed to Git +# It will be validated/recreated in run.sh after Maven compilation completes echo "=== Hybrid Compilation for Maven 4 ===" echo @@ -66,53 +68,41 @@ echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile +mvn clean package -# Create JARs for Maven-compiled modules -echo -echo "Step 3: Package Maven-compiled modules as JARs in mlib/" -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar ${JAR_OPTIONS} --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" ${JAR_OPTIONS} --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 echo echo "Step 4: Manually compile modfoo (requires modauto1)" pushd ../src/modfoo > /dev/null 2>&1 mkdir -p ../../m4/mods/modfoo -echo "javac ${JAVAC_OPTIONS} -d ../../m4/mods/modfoo --module-path ../../m4/mlib${PATH_SEPARATOR}../../m4/amlib1 --release 11 \$(find . -name \"*.java\")" +echo "javac ${JAVAC_OPTIONS} -d ../../m4/mods/modfoo --module-path ../../m4/target${PATH_SEPARATOR}../../m4/amlib1 --release 11 \$(find . -name \"*.java\")" # shellcheck disable=SC2046,SC2086 # find output needs word splitting, JAVAC_OPTIONS intentionally unquoted "${COMPILE_JAVA_HOME}/bin/javac" ${JAVAC_OPTIONS} -d ../../m4/mods/modfoo \ - --module-path ../../m4/mlib"${PATH_SEPARATOR}"../../m4/amlib1 \ + --module-path ../../m4/target"${PATH_SEPARATOR}"../../m4/amlib1 \ --release 11 \ $(find . -name "*.java") 2>&1 -echo "jar ${JAR_OPTIONS} --create --file=../../m4/mlib/modfoo.jar -C ../../m4/mods/modfoo ." +echo "jar ${JAR_OPTIONS} --create --file=../../m4/target/modfoo.jar -C ../../m4/mods/modfoo ." # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting -"${COMPILE_JAVA_HOME}/bin/jar" ${JAR_OPTIONS} --create --file=../../m4/mlib/modfoo.jar -C ../../m4/mods/modfoo . 2>&1 +"${COMPILE_JAVA_HOME}/bin/jar" ${JAR_OPTIONS} --create --file=../../m4/target/modfoo.jar -C ../../m4/mods/modfoo . 2>&1 popd >/dev/null 2>&1 echo echo "Step 5: Manually compile modbar (requires modauto2)" pushd ../src/modbar > /dev/null 2>&1 mkdir -p ../../m4/mods/modbar -echo "javac ${JAVAC_OPTIONS} -d ../../m4/mods/modbar --module-path ../../m4/mlib${PATH_SEPARATOR}../../m4/amlib2 --release 11 \$(find . -name \"*.java\")" +echo "javac ${JAVAC_OPTIONS} -d ../../m4/mods/modbar --module-path ../../m4/target${PATH_SEPARATOR}../../m4/amlib2 --release 11 \$(find . -name \"*.java\")" # shellcheck disable=SC2046,SC2086 # find output needs word splitting, JAVAC_OPTIONS intentionally unquoted "${COMPILE_JAVA_HOME}/bin/javac" ${JAVAC_OPTIONS} -d ../../m4/mods/modbar \ - --module-path ../../m4/mlib"${PATH_SEPARATOR}"../../m4/amlib2 \ + --module-path ../../m4/target"${PATH_SEPARATOR}"../../m4/amlib2 \ --release 11 \ $(find . -name "*.java") 2>&1 -echo "jar ${JAR_OPTIONS} --create --file=../../m4/mlib/modbar.jar -C ../../m4/mods/modbar ." +echo "jar ${JAR_OPTIONS} --create --file=../../m4/target/modbar.jar -C ../../m4/mods/modbar ." # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting -"${COMPILE_JAVA_HOME}/bin/jar" ${JAR_OPTIONS} --create --file=../../m4/mlib/modbar.jar -C ../../m4/mods/modbar . 2>&1 +"${COMPILE_JAVA_HOME}/bin/jar" ${JAR_OPTIONS} --create --file=../../m4/target/modbar.jar -C ../../m4/mods/modbar . 2>&1 popd >/dev/null 2>&1 echo diff --git a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/mlib b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/mlib new file mode 120000 index 00000000..1de56593 --- /dev/null +++ b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/mlib @@ -0,0 +1 @@ +target \ No newline at end of file diff --git a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/pom.xml b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/pom.xml index 402b0fdd..6ed82a1a 100644 --- a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/pom.xml +++ b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/pom.xml @@ -20,11 +20,9 @@ modcommon - src/modcommon/main/java modmain - src/modmain/main/java @@ -34,6 +32,41 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modcommon + package + + jar + + + ${project.build.outputDirectory}/modcommon + modcommon + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/run.sh b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/run.sh index 9da5f958..be073806 100755 --- a/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/run.sh +++ b/jigsaw-examples/example_layer-modules-grouped-in-hierarchy/m4/run.sh @@ -24,10 +24,26 @@ echo # Create run-result directory if it doesn't exist mkdir -p run-result +# Setup mlib for module-path access +# Windows: Copy JARs to mlib/ directory (symlinks cause AccessDeniedException) +# Unix: Use symlink to target/ +if [ "${OS:-$(uname)}" = "Windows_NT" ]; then + # Windows: Ensure mlib is a directory, copy JARs + echo "We are on Windows, copying JARs to mlib/" + rm -rf mlib + mkdir -p mlib + cp -p target/*.jar mlib/ + ls -l mlib/ +else + # Unix: Ensure mlib is a symlink to target + echo "We are on Unix, using JARs from mlib/ as symlink" + test -h mlib || ln -sfn target mlib +fi + # Run the Java code with mlib on module-path # Note: Automatic modules are not needed at runtime for this example # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \ - --module-path mlib \ + --module-path target \ --module modmain/pkgmain.Main . \ 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_layer-modules-module-resolution/README.adoc b/jigsaw-examples/example_layer-modules-module-resolution/README.adoc index 55ed604f..9a9935eb 100644 --- a/jigsaw-examples/example_layer-modules-module-resolution/README.adoc +++ b/jigsaw-examples/example_layer-modules-module-resolution/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -116,20 +116,41 @@ The `` element expects one source location per module name. Solution:: Hybrid compilation approach in `m4/compile.sh`: + -. Maven compiles the primary modules including modcommon v1.0 via the standard Module Source Hierarchy +. Maven compiles all primary modules (modbar, modcommon v1.0, modfoo, modmain, modversion1, modversion2) using Module Source Hierarchy +** Maven creates JARs in `target/` using maven-jar-plugin with classifiers +. The compile script copies layer-specific JARs to their respective directories for dynamic module loading: ++ +[source,bash] +---- +# Copy foo layer modules (modfoo, modversion1) to foomlib/ +for mod in modfoo modversion1; do + cp "target/example_layer-modules-module-resolution-m4-1.0-${mod}.jar" "foomlib/${mod}.jar" +done + +# Copy bar layer modules (modbar, modversion2) to barmlib/ +for mod in modbar modversion2; do + cp "target/example_layer-modules-module-resolution-m4-1.0-${mod}.jar" "barmlib/${mod}.jar" +done +---- ++ . Manual javac invocation compiles modcommon v2.0 from src2/: + [source,bash] ---- javac -d mods2 --release 11 --module-version=2.0 \ - --module-path mlib --module-source-path ../src2 \ + --module-path target --module-source-path ../src2 \ $(find ../src2/modcommon -name "*.java") + +jar --create --file=../barmlib/modcommon.jar -C modcommon . ---- + -. JAR placement follows the original structure: -** mlib/ - boot layer modules (modcommon v1.0, modmain) -** foomlib/ - foo layer modules (modfoo, modversion1) -** barmlib/ - bar layer modules (modbar, modversion2, modcommon v2.0) +. JAR placement for dynamic module loading: +** target/ - Maven-built JARs (with classifiers) +** mlib/ - Boot layer modules (OS-specific: Unix uses symlink to target/, Windows uses directory with copied JARs) +** foomlib/ - foo layer modules (modfoo, modversion1) copied from target/ +** barmlib/ - bar layer modules (modbar, modversion2) copied from target/, plus modcommon v2.0 compiled manually ++ +The `run.sh` script creates `mlib` using OS-specific approaches to avoid `AccessDeniedException` when Java's `ModuleLayer` API traverses symlinks on Windows. This hybrid approach is necessary because: diff --git a/jigsaw-examples/example_layer-modules-module-resolution/m4/clean.sh b/jigsaw-examples/example_layer-modules-module-resolution/m4/clean.sh index 25d409c6..e156016d 100755 --- a/jigsaw-examples/example_layer-modules-module-resolution/m4/clean.sh +++ b/jigsaw-examples/example_layer-modules-module-resolution/m4/clean.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf foomlib rm -rf barmlib rm -rf mods2 +# Only remove mlib on Windows (where it's a directory with copied JARs) +# On Unix, mlib is a committed symlink and should remain +[ "${OS:-$(uname)}" = "Windows_NT" ] && rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_layer-modules-module-resolution/m4/compile.sh b/jigsaw-examples/example_layer-modules-module-resolution/m4/compile.sh index 667a9ff6..17bf2665 100755 --- a/jigsaw-examples/example_layer-modules-module-resolution/m4/compile.sh +++ b/jigsaw-examples/example_layer-modules-module-resolution/m4/compile.sh @@ -20,53 +20,36 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib mkdir -p foomlib mkdir -p barmlib +# Note: mlib → target symlink is committed to Git +# It will be validated/recreated in run.sh after Maven compilation completes + echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs in appropriate directories (matching original compile.sh structure) -pushd target/classes > /dev/null 2>&1 +mvn clean package -# Boot layer modules go to mlib -for mod in modcommon modmain; -do - if [ -d "${mod}" ]; then - echo "jar $JAR_OPTIONS --create --file=../../mlib/${mod}.jar -C ${mod} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${mod}.jar" -C "${mod}" . 2>&1 - fi -done +# Copy Maven-built JARs to layer-specific directories for dynamic module loading +echo +echo "Copying JARs to layer-specific directories..." -# Foo layer modules go to foomlib -for mod in modversion1 modfoo; -do - if [ -d "${mod}" ]; then - echo "jar $JAR_OPTIONS --create --file=../../foomlib/${mod}.jar -C ${mod} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../foomlib/${mod}.jar" -C "${mod}" . 2>&1 - fi +# Copy foo layer modules (modfoo, modversion1) to foomlib/ +for mod in modfoo modversion1; do + echo "cp target/example_layer-modules-module-resolution-m4-1.0-${mod}.jar foomlib/${mod}.jar" + cp "target/example_layer-modules-module-resolution-m4-1.0-${mod}.jar" "foomlib/${mod}.jar" done -# Bar layer modules go to barmlib -for mod in modversion2 modbar; -do - if [ -d "${mod}" ]; then - echo "jar $JAR_OPTIONS --create --file=../../barmlib/${mod}.jar -C ${mod} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../barmlib/${mod}.jar" -C "${mod}" . 2>&1 - fi +# Copy bar layer modules (modbar, modversion2) to barmlib/ +for mod in modbar modversion2; do + echo "cp target/example_layer-modules-module-resolution-m4-1.0-${mod}.jar barmlib/${mod}.jar" + cp "target/example_layer-modules-module-resolution-m4-1.0-${mod}.jar" "barmlib/${mod}.jar" done -popd >/dev/null 2>&1 - # Compile second version of modcommon from src2 (version 2.0) # Maven doesn't support multiple versions of the same module, so we compile manually echo @@ -79,9 +62,9 @@ if [ -n "${JAVA11_HOME:-}" ]; then COMPILE_JAVA_HOME="${JAVA11_HOME}" fi -echo "javac ${JAVAC_OPTIONS} -d mods2 --release 11 --module-version=2.0 --module-path mlib --module-source-path ../src2 \$(find ../src2/modcommon -name \"*.java\")" +echo "javac ${JAVAC_OPTIONS} -d mods2 --release 11 --module-version=2.0 --module-path target --module-source-path ../src2 \$(find ../src2/modcommon -name \"*.java\")" # shellcheck disable=SC2046,SC2086 # JAVAC_OPTIONS is intentionally unquoted for word splitting, the find command is intended to be expanded -"${COMPILE_JAVA_HOME}/bin/javac" ${JAVAC_OPTIONS} -d mods2 --release 11 --module-version=2.0 --module-path mlib --module-source-path ../src2 $(find ../src2/modcommon -name "*.java") 2>&1 +"${COMPILE_JAVA_HOME}/bin/javac" ${JAVAC_OPTIONS} -d mods2 --release 11 --module-version=2.0 --module-path target --module-source-path ../src2 $(find ../src2/modcommon -name "*.java") 2>&1 # Package new modcommon v2.0 as jar in barmlib (overwrites v1.0) pushd mods2 > /dev/null 2>&1 diff --git a/jigsaw-examples/example_layer-modules-module-resolution/m4/mlib b/jigsaw-examples/example_layer-modules-module-resolution/m4/mlib new file mode 120000 index 00000000..1de56593 --- /dev/null +++ b/jigsaw-examples/example_layer-modules-module-resolution/m4/mlib @@ -0,0 +1 @@ +target \ No newline at end of file diff --git a/jigsaw-examples/example_layer-modules-module-resolution/m4/pom.xml b/jigsaw-examples/example_layer-modules-module-resolution/m4/pom.xml index d6b04780..38f735af 100644 --- a/jigsaw-examples/example_layer-modules-module-resolution/m4/pom.xml +++ b/jigsaw-examples/example_layer-modules-module-resolution/m4/pom.xml @@ -18,27 +18,21 @@ modbar - src/modbar/main/java modcommon - src/modcommon/main/java modfoo - src/modfoo/main/java modmain - src/modmain/main/java modversion1 - src/modversion1/main/java modversion2 - src/modversion2/main/java @@ -48,6 +42,85 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modbar + package + + jar + + + ${project.build.outputDirectory}/modbar + modbar + + + + modcommon + package + + jar + + + ${project.build.outputDirectory}/modcommon + modcommon + + + + modfoo + package + + jar + + + ${project.build.outputDirectory}/modfoo + modfoo + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + modversion1 + package + + jar + + + ${project.build.outputDirectory}/modversion1 + modversion1 + + + + modversion2 + package + + jar + + + ${project.build.outputDirectory}/modversion2 + modversion2 + + + + diff --git a/jigsaw-examples/example_layer-modules-module-resolution/m4/run.sh b/jigsaw-examples/example_layer-modules-module-resolution/m4/run.sh index c3662b74..bede3efe 100755 --- a/jigsaw-examples/example_layer-modules-module-resolution/m4/run.sh +++ b/jigsaw-examples/example_layer-modules-module-resolution/m4/run.sh @@ -15,6 +15,22 @@ echo # Create run-result directory if it doesn't exist mkdir -p run-result +# Setup mlib for module-path access +# Windows: Copy JARs to mlib/ directory (symlinks cause AccessDeniedException) +# Unix: Use symlink to target/ +if [ "${OS:-$(uname)}" = "Windows_NT" ]; then + # Windows: Ensure mlib is a directory, copy JARs + echo "We are on Windows, copying JARs to mlib/" + rm -rf mlib + mkdir -p mlib + cp -p target/*.jar mlib/ + ls -l mlib/ +else + # Unix: Ensure mlib is a symlink to target + echo "We are on Unix, using JARs from mlib/ as symlink" + test -h mlib || ln -sfn target mlib +fi + # Run the Java code with "." argument for dynamic layer creation, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${RUNTIME_JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main . 2>&1 | normalize | tee run-result/run.txt | myecho +"${RUNTIME_JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main . 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_maven-project/README.adoc b/jigsaw-examples/example_maven-project/README.adoc index b78e0601..9151729e 100644 --- a/jigsaw-examples/example_maven-project/README.adoc +++ b/jigsaw-examples/example_maven-project/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_maven-test-blackbox/README.adoc b/jigsaw-examples/example_maven-test-blackbox/README.adoc index bce858f7..0bd8d883 100644 --- a/jigsaw-examples/example_maven-test-blackbox/README.adoc +++ b/jigsaw-examples/example_maven-test-blackbox/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_maven-test-whitebox/README.adoc b/jigsaw-examples/example_maven-test-whitebox/README.adoc index 5a2b4393..8384b252 100644 --- a/jigsaw-examples/example_maven-test-whitebox/README.adoc +++ b/jigsaw-examples/example_maven-test-whitebox/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_naming-modules/README.adoc b/jigsaw-examples/example_naming-modules/README.adoc index cbdf44f5..52e0bff9 100644 --- a/jigsaw-examples/example_naming-modules/README.adoc +++ b/jigsaw-examples/example_naming-modules/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_naming-modules/m4/clean.sh b/jigsaw-examples/example_naming-modules/m4/clean.sh index fb1bc068..f6185e1f 100755 --- a/jigsaw-examples/example_naming-modules/m4/clean.sh +++ b/jigsaw-examples/example_naming-modules/m4/clean.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result rm -rf classes rm -rf amlib1 diff --git a/jigsaw-examples/example_naming-modules/m4/compile.sh b/jigsaw-examples/example_naming-modules/m4/compile.sh index 38ac707a..b4e125ed 100755 --- a/jigsaw-examples/example_naming-modules/m4/compile.sh +++ b/jigsaw-examples/example_naming-modules/m4/compile.sh @@ -20,7 +20,6 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib mkdir -p amlib1 mkdir -p amlib2 mkdir -p amlib3 @@ -65,22 +64,10 @@ echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile +mvn clean package -# Create JARs for explicit modules -echo -echo "Step 3: Create modular JARs" -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar ${JAR_OPTIONS} --create --file=../../mlib/${MODDIR}.jar --module-version 0.1 -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" --module-version 0.1 -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 echo echo "✅ Compilation complete" diff --git a/jigsaw-examples/example_naming-modules/m4/pom.xml b/jigsaw-examples/example_naming-modules/m4/pom.xml index 95432162..5e7d8cda 100644 --- a/jigsaw-examples/example_naming-modules/m4/pom.xml +++ b/jigsaw-examples/example_naming-modules/m4/pom.xml @@ -7,7 +7,7 @@ com.example.jigsaw example_naming-modules-m4 - 1.0-SNAPSHOT + 0.1 11 @@ -29,19 +29,15 @@ mod.client - src/mod.client/main/java mod_client - src/mod_client/main/java modjava - src/modjava/main/java modmain - src/modmain/main/java @@ -51,6 +47,85 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + java.whatever + package + + jar + + + ${project.build.outputDirectory}/java.whatever + java.whatever + + + + jdk.whatever + package + + jar + + + ${project.build.outputDirectory}/jdk.whatever + jdk.whatever + + + + mod.client + package + + jar + + + ${project.build.outputDirectory}/mod.client + mod.client + + + + mod_client + package + + jar + + + ${project.build.outputDirectory}/mod_client + mod_client + + + + modjava + package + + jar + + + ${project.build.outputDirectory}/modjava + modjava + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_naming-modules/m4/run.sh b/jigsaw-examples/example_naming-modules/m4/run.sh index 3482b571..60dc2368 100755 --- a/jigsaw-examples/example_naming-modules/m4/run.sh +++ b/jigsaw-examples/example_naming-modules/m4/run.sh @@ -16,7 +16,7 @@ echo "Using Java version:" echo # Iterate through all JAR directories (modular and automatic modules) -for dir in mlib amlib1 amlib2 amlib3 amlib4 +for dir in target amlib1 amlib2 amlib3 amlib4 do pushd "${dir}" > /dev/null 2>&1 # shellcheck disable=SC2012,SC2035 # JAR filenames are controlled, safe to use ls with glob @@ -25,7 +25,14 @@ do echo "JAR-file: ${JAR} in ${dir}" # get name of JAR-file - MOD="$(basename "${JAR}" | sed s/'.jar'//g | sed s/'-'/'.'/g | cut -d '.' -f 1-2)" + # For target/ JARs (Phase 2): extract classifier after last hyphen before .jar + # For amlib JARs: use the whole basename + if [[ "${dir}" == "target" ]]; then + # Extract classifier from pattern: artifactId-version-classifier.jar + MOD="$(basename "${JAR}" .jar | sed 's/.*-\([^-]*\)$/\1/')" + else + MOD="$(basename "${JAR}" | sed s/'.jar'//g | sed s/'-'/'.'/g | cut -d '.' -f 1-2)" + fi echo "java --module-path . --module ${MOD}/pkgmain.Main" if ! "${JAVA_HOME}/bin/java" --module-path . --module "${MOD}/pkgmain.Main" 2>&1 | normalize | tee -a "../${result_dir}/run.txt" | myecho; then diff --git a/jigsaw-examples/example_patch/README.adoc b/jigsaw-examples/example_patch/README.adoc index d1198a6c..82050292 100644 --- a/jigsaw-examples/example_patch/README.adoc +++ b/jigsaw-examples/example_patch/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -127,19 +127,49 @@ m4/src/modb/main/java -> ../../../../src/modb m4/src/modb-patch/main/java -> ../../../../src/modb-patch ---- + -These symbolic links are checked into Git and do not need to be created dynamically. +These source symlinks point to the original shared source directories and are checked into Git. + + [NOTE] ==== The patch compilation uses `--patch-module modb=src/modb-patch/main/java`, pointing directly to the symlinked patch sources. This maintains full consistency with the `src//main/java` directory pattern throughout the `m4/` migration. -Dependencies from the original `modb` module (like the `Helper` class) are resolved via `--module-path target/classes`. +Dependencies from the original `modb` module (like the `Helper` class) are automatically resolved via `--module-path target/classes`. +==== + + +Module-path access via mlib:: ++ +Maven (4) uses maven-jar-plugin with classifiers, creating JARs with names like: ++ +[source] +---- +target/example_patch-m4-1.0-SNAPSHOT-modmain.jar +target/example_patch-m4-1.0-SNAPSHOT-modb.jar +---- ++ +However, Java's `--module-path` works best with simple JAR names or explicit paths. +The `run.sh` script creates `mlib` to provide module-path access using OS-specific approaches: + +Unix/macOS:::: Creates symlink `mlib → target` (using `ln -sfn`) +Windows:::: Creates directory `mlib/` and copies JARs from `target/` + ++ +The Windows approach avoids `AccessDeniedException` issues when Java's module system traverses symlinks that were checked out before the `target/` directory existed. + ++ +[NOTE] +==== +A committed symlink `m4/mlib → target` exists in Git for convenience on Unix systems. +On Windows, this symlink is replaced with a directory and copied JARs at runtime by `run.sh`. +Both approaches provide the same functionality: `--module-path mlib` accesses the Maven-built JARs. ==== Build artifacts:: + +* `target/` - Maven-built JARs with classifiers (example_patch-m4-1.0-SNAPSHOT-modmain.jar, etc.) * `target/classes/` - Maven-compiled module classes -* `mlib/` - Module JARs (modmain.jar, modb.jar) +* `mlib/` - Symlink to `target/` for module-path compatibility * `patches/modb/` - Exploded patch classes * `patchlib/modb.jar` - Patch JAR diff --git a/jigsaw-examples/example_patch/m4/.gitignore b/jigsaw-examples/example_patch/m4/.gitignore index 3ca66262..5d3dc5e3 100644 --- a/jigsaw-examples/example_patch/m4/.gitignore +++ b/jigsaw-examples/example_patch/m4/.gitignore @@ -1,12 +1,11 @@ # Maven build output /target -# Module JARs -/mlib - -# Patch artifacts /patches /patchlib +# Module library (symlink on Unix, directory on Windows) +/mlib + # Run results /run-result diff --git a/jigsaw-examples/example_patch/m4/clean.sh b/jigsaw-examples/example_patch/m4/clean.sh index 16944b56..539aa915 100755 --- a/jigsaw-examples/example_patch/m4/clean.sh +++ b/jigsaw-examples/example_patch/m4/clean.sh @@ -4,9 +4,11 @@ set -eu -o pipefail echo "Cleaning Maven 4 build artifacts..." rm -rf target -rm -rf mlib rm -rf patches rm -rf patchlib +# Only remove mlib on Windows (where it's a directory with copied JARs) +# On Unix, mlib is a committed symlink and should remain +[ "${OS:-$(uname)}" = "Windows_NT" ] && rm -rf mlib rm -rf run-result echo "✅ Clean complete" diff --git a/jigsaw-examples/example_patch/m4/compile.sh b/jigsaw-examples/example_patch/m4/compile.sh index b46af0fd..51abae87 100755 --- a/jigsaw-examples/example_patch/m4/compile.sh +++ b/jigsaw-examples/example_patch/m4/compile.sh @@ -18,31 +18,23 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib mkdir -p patches mkdir -p patchlib +# Note: mlib → target symlink is committed to Git +# It will be validated/recreated in run.sh after Maven compilation completes + echo "=== Step 1: Compile modules modmain and modb with Maven 4 ====" echo echo "mvn --version" mvn --version echo -echo "mvn clean compile" -mvn clean compile +echo "mvn clean package" +echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" +mvn clean package echo -# Create JARs from Maven-compiled classes -echo "=== Step 2: Create module JARs ====" -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar ${JAR_OPTIONS} --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" ${JAR_OPTIONS} --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 echo # Compile the patch as classes, create (non-modular) jar. diff --git a/jigsaw-examples/example_patch/m4/mlib b/jigsaw-examples/example_patch/m4/mlib new file mode 120000 index 00000000..1de56593 --- /dev/null +++ b/jigsaw-examples/example_patch/m4/mlib @@ -0,0 +1 @@ +target \ No newline at end of file diff --git a/jigsaw-examples/example_patch/m4/pom.xml b/jigsaw-examples/example_patch/m4/pom.xml index 2f493738..250f6437 100644 --- a/jigsaw-examples/example_patch/m4/pom.xml +++ b/jigsaw-examples/example_patch/m4/pom.xml @@ -21,11 +21,9 @@ modmain - src/modmain/main/java modb - src/modb/main/java @@ -35,6 +33,41 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + diff --git a/jigsaw-examples/example_patch/m4/run.sh b/jigsaw-examples/example_patch/m4/run.sh index fc533c58..ce4d6b6d 100755 --- a/jigsaw-examples/example_patch/m4/run.sh +++ b/jigsaw-examples/example_patch/m4/run.sh @@ -9,6 +9,22 @@ result_dir="${1:-run-result}" rm -rf "${result_dir}" mkdir -p "${result_dir}" +# Setup mlib for module-path access +# Windows: Copy JARs to mlib/ directory (symlinks cause AccessDeniedException) +# Unix: Use symlink to target/ +if [ "${OS:-$(uname)}" = "Windows_NT" ]; then + # Windows: Ensure mlib is a directory, copy JARs + echo "We are on Windows, copying JARs to mlib/" + rm -rf mlib + mkdir -p mlib + cp -p target/*.jar mlib/ + ls -l mlib/ +else + # Unix: Ensure mlib is a symlink to target + echo "We are on Unix, using JARs from mlib/ as symlink" + test -h mlib || ln -sfn target mlib +fi + # Show Java version for user information echo "Using Java version:" "${JAVA_HOME}/bin/java" -version diff --git a/jigsaw-examples/example_reflection/README.adoc b/jigsaw-examples/example_reflection/README.adoc index a929b2ea..8ed6bafc 100644 --- a/jigsaw-examples/example_reflection/README.adoc +++ b/jigsaw-examples/example_reflection/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_reflection/m4/.gitignore b/jigsaw-examples/example_reflection/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_reflection/m4/.gitignore +++ b/jigsaw-examples/example_reflection/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_reflection/m4/clean.sh b/jigsaw-examples/example_reflection/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_reflection/m4/clean.sh +++ b/jigsaw-examples/example_reflection/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_reflection/m4/compile.sh b/jigsaw-examples/example_reflection/m4/compile.sh index d8c08959..3d6b7cb8 100755 --- a/jigsaw-examples/example_reflection/m4/compile.sh +++ b/jigsaw-examples/example_reflection/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar ${JAR_OPTIONS} --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_reflection/m4/pom.xml b/jigsaw-examples/example_reflection/m4/pom.xml index 24bcd59e..ff15d978 100644 --- a/jigsaw-examples/example_reflection/m4/pom.xml +++ b/jigsaw-examples/example_reflection/m4/pom.xml @@ -18,11 +18,9 @@ modb - src/modb/main/java modmain - src/modmain/main/java @@ -32,6 +30,41 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_reflection/m4/run.sh b/jigsaw-examples/example_reflection/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_reflection/m4/run.sh +++ b/jigsaw-examples/example_reflection/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_requires-static/README.adoc b/jigsaw-examples/example_requires-static/README.adoc index 2c0c115c..ac4abca8 100644 --- a/jigsaw-examples/example_requires-static/README.adoc +++ b/jigsaw-examples/example_requires-static/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_requires-static/m4/.gitignore b/jigsaw-examples/example_requires-static/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_requires-static/m4/.gitignore +++ b/jigsaw-examples/example_requires-static/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_requires-static/m4/clean.sh b/jigsaw-examples/example_requires-static/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_requires-static/m4/clean.sh +++ b/jigsaw-examples/example_requires-static/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_requires-static/m4/compile.sh b/jigsaw-examples/example_requires-static/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_requires-static/m4/compile.sh +++ b/jigsaw-examples/example_requires-static/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_requires-static/m4/pom.xml b/jigsaw-examples/example_requires-static/m4/pom.xml index 5f56534d..ecfb5173 100644 --- a/jigsaw-examples/example_requires-static/m4/pom.xml +++ b/jigsaw-examples/example_requires-static/m4/pom.xml @@ -19,15 +19,12 @@ modmain - src/modmain/main/java modb - src/modb/main/java modc - src/modc/main/java @@ -37,6 +34,52 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modc + package + + jar + + + ${project.build.outputDirectory}/modc + modc + + + + diff --git a/jigsaw-examples/example_requires-static/m4/run.sh b/jigsaw-examples/example_requires-static/m4/run.sh index c93f6a53..897f5323 100755 --- a/jigsaw-examples/example_requires-static/m4/run.sh +++ b/jigsaw-examples/example_requires-static/m4/run.sh @@ -16,4 +16,4 @@ mkdir -p run-result # because of the 'requires static' dependencies from modb->modc and modmain->modb, # we need to add modb and modc explicitly to the runtime Configuration # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --add-modules modb,modc --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --add-modules modb,modc --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_requires_exports-to/README.adoc b/jigsaw-examples/example_requires_exports-to/README.adoc index 43917993..aa7afdf3 100644 --- a/jigsaw-examples/example_requires_exports-to/README.adoc +++ b/jigsaw-examples/example_requires_exports-to/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_requires_exports-to/m4/.gitignore b/jigsaw-examples/example_requires_exports-to/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_requires_exports-to/m4/.gitignore +++ b/jigsaw-examples/example_requires_exports-to/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_requires_exports-to/m4/clean.sh b/jigsaw-examples/example_requires_exports-to/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_requires_exports-to/m4/clean.sh +++ b/jigsaw-examples/example_requires_exports-to/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_requires_exports-to/m4/compile.sh b/jigsaw-examples/example_requires_exports-to/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_requires_exports-to/m4/compile.sh +++ b/jigsaw-examples/example_requires_exports-to/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_requires_exports-to/m4/pom.xml b/jigsaw-examples/example_requires_exports-to/m4/pom.xml index 44cfbf44..349aa072 100644 --- a/jigsaw-examples/example_requires_exports-to/m4/pom.xml +++ b/jigsaw-examples/example_requires_exports-to/m4/pom.xml @@ -18,19 +18,15 @@ modb1 - src/modb1/main/java modb2 - src/modb2/main/java modc - src/modc/main/java modmain - src/modmain/main/java @@ -40,6 +36,63 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb1 + package + + jar + + + ${project.build.outputDirectory}/modb1 + modb1 + + + + modb2 + package + + jar + + + ${project.build.outputDirectory}/modb2 + modb2 + + + + modc + package + + jar + + + ${project.build.outputDirectory}/modc + modc + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_requires_exports-to/m4/run.sh b/jigsaw-examples/example_requires_exports-to/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_requires_exports-to/m4/run.sh +++ b/jigsaw-examples/example_requires_exports-to/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_requires_exports/README.adoc b/jigsaw-examples/example_requires_exports/README.adoc index 21209de9..04943315 100644 --- a/jigsaw-examples/example_requires_exports/README.adoc +++ b/jigsaw-examples/example_requires_exports/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_requires_exports/m4/.gitignore b/jigsaw-examples/example_requires_exports/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_requires_exports/m4/.gitignore +++ b/jigsaw-examples/example_requires_exports/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_requires_exports/m4/clean.sh b/jigsaw-examples/example_requires_exports/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_requires_exports/m4/clean.sh +++ b/jigsaw-examples/example_requires_exports/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_requires_exports/m4/compile.sh b/jigsaw-examples/example_requires_exports/m4/compile.sh index f872668c..37682871 100755 --- a/jigsaw-examples/example_requires_exports/m4/compile.sh +++ b/jigsaw-examples/example_requires_exports/m4/compile.sh @@ -20,23 +20,10 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib - echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package diff --git a/jigsaw-examples/example_requires_exports/m4/pom.xml b/jigsaw-examples/example_requires_exports/m4/pom.xml index 84327bf1..d1392389 100644 --- a/jigsaw-examples/example_requires_exports/m4/pom.xml +++ b/jigsaw-examples/example_requires_exports/m4/pom.xml @@ -18,15 +18,12 @@ modmain - src/modmain/main/java modb - src/modb/main/java modc - src/modc/main/java @@ -36,6 +33,52 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modc + package + + jar + + + ${project.build.outputDirectory}/modc + modc + + + + diff --git a/jigsaw-examples/example_requires_exports/m4/run.sh b/jigsaw-examples/example_requires_exports/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_requires_exports/m4/run.sh +++ b/jigsaw-examples/example_requires_exports/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/README.adoc b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/README.adoc index 970e2eef..11efcac6 100644 --- a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/README.adoc +++ b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/.gitignore b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/.gitignore +++ b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/clean.sh b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/clean.sh +++ b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/compile.sh b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/compile.sh +++ b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/pom.xml b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/pom.xml index f4e251a9..a5e09781 100644 --- a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/pom.xml +++ b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/pom.xml @@ -18,27 +18,21 @@ moda - src/moda/main/java modb - src/modb/main/java modc - src/modc/main/java modfacade - src/modfacade/main/java modmain - src/modmain/main/java modmainbehindfacade - src/modmainbehindfacade/main/java @@ -48,6 +42,85 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + moda + package + + jar + + + ${project.build.outputDirectory}/moda + moda + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modc + package + + jar + + + ${project.build.outputDirectory}/modc + modc + + + + modfacade + package + + jar + + + ${project.build.outputDirectory}/modfacade + modfacade + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + modmainbehindfacade + package + + jar + + + ${project.build.outputDirectory}/modmainbehindfacade + modmainbehindfacade + + + + diff --git a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/run.sh b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/run.sh index ca09801b..6cf5bf8d 100755 --- a/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/run.sh +++ b/jigsaw-examples/example_requires_exports_requires-transitive_exports-to/m4/run.sh @@ -18,11 +18,11 @@ mkdir -p run-result # Run first main class, save output to run-result/run.txt # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt # Add separator echo " " | tee -a run-result/run.txt # Run second main class, append output to run-result/run.txt # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmainbehindfacade/pkgmainbehindfacade.MainBehindFacade 2>&1 | normalize | tee -a run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmainbehindfacade/pkgmainbehindfacade.MainBehindFacade 2>&1 | normalize | tee -a run-result/run.txt | myecho diff --git a/jigsaw-examples/example_resolved-modules/README.adoc b/jigsaw-examples/example_resolved-modules/README.adoc index 3ad8f93b..f2f33f7b 100644 --- a/jigsaw-examples/example_resolved-modules/README.adoc +++ b/jigsaw-examples/example_resolved-modules/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -116,3 +116,38 @@ Scenario 8 demonstrates creating a custom runtime image using `jlink`. Automatic Module Reference:: The run script references `../amlib` for the `javax.json` automatic module in scenario 5, demonstrating that automatic modules are only loaded when explicitly required or added. + +=== JAR Naming for Module-Path and jlink + +Maven (4) uses maven-jar-plugin with classifiers, creating JARs with names like: + +[source] +---- +target/example_resolved-modules-m4-1.0-SNAPSHOT-moda.jar +target/example_resolved-modules-m4-1.0-SNAPSHOT-modb.jar +target/example_resolved-modules-m4-1.0-SNAPSHOT-modc.jar +---- + +However, when using `jlink`, it outputs the actual JAR filenames in its verbose output. The golden master test expects simple JAR names (e.g., `moda.jar`) for consistency with the original example. + +To solve this, `compile.sh` copies the JARs to `mlib/` with simple names: + +[source,bash] +---- +# Copy JARs to mlib with simple names for jlink +for mod in moda modb modc; do + cp "target/example_resolved-modules-m4-1.0-SNAPSHOT-${mod}.jar" "mlib/${mod}.jar" +done +---- + +The `run.sh` script then uses `--module-path mlib` instead of `--module-path target`, ensuring: + +* Simple JAR names in jlink output (matches golden master expectations) +* Consistent module-path references throughout all 8 test scenarios +* Compatibility with both direct Java execution and jlink-created runtime images + +[NOTE] +==== +While `--module-path target` would work for direct Java execution, jlink would output the full classifier-based names, breaking golden master verification. +The JAR copying approach maintains output consistency across all scenarios. +==== diff --git a/jigsaw-examples/example_resolved-modules/m4/clean.sh b/jigsaw-examples/example_resolved-modules/m4/clean.sh index f49447ad..19a940b1 100755 --- a/jigsaw-examples/example_resolved-modules/m4/clean.sh +++ b/jigsaw-examples/example_resolved-modules/m4/clean.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf jimage rm -rf run-result diff --git a/jigsaw-examples/example_resolved-modules/m4/compile.sh b/jigsaw-examples/example_resolved-modules/m4/compile.sh index f872668c..13ffd537 100755 --- a/jigsaw-examples/example_resolved-modules/m4/compile.sh +++ b/jigsaw-examples/example_resolved-modules/m4/compile.sh @@ -26,17 +26,16 @@ echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 +mvn clean package + +# Copy JARs to mlib with simple names for jlink +# (jlink outputs the JAR filename in its output, and we need simple names) +echo +echo "Copying JARs to mlib with simple names..." +for mod in moda modb modc; do + echo "cp target/example_resolved-modules-m4-1.0-SNAPSHOT-${mod}.jar mlib/${mod}.jar" + cp "target/example_resolved-modules-m4-1.0-SNAPSHOT-${mod}.jar" "mlib/${mod}.jar" done -popd >/dev/null 2>&1 + diff --git a/jigsaw-examples/example_resolved-modules/m4/pom.xml b/jigsaw-examples/example_resolved-modules/m4/pom.xml index 8cc9790d..81bda7ce 100644 --- a/jigsaw-examples/example_resolved-modules/m4/pom.xml +++ b/jigsaw-examples/example_resolved-modules/m4/pom.xml @@ -18,15 +18,12 @@ moda - src/moda/main/java modb - src/modb/main/java modc - src/modc/main/java @@ -36,6 +33,52 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + moda + package + + jar + + + ${project.build.outputDirectory}/moda + moda + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modc + package + + jar + + + ${project.build.outputDirectory}/modc + modc + + + + diff --git a/jigsaw-examples/example_resolved-modules/m4/run.sh b/jigsaw-examples/example_resolved-modules/m4/run.sh index b3a462c8..9b78e6c8 100755 --- a/jigsaw-examples/example_resolved-modules/m4/run.sh +++ b/jigsaw-examples/example_resolved-modules/m4/run.sh @@ -27,42 +27,42 @@ echo echo "1." echo "Running with root-module moda" -echo " java --module-path mlib --module moda/pkga.AMain" +echo " java --module-path target --module moda/pkga.AMain" "${JAVA_HOME}/bin/java" --module-path mlib --module moda/pkga.AMain 2>&1 | normalize | tee "${result_dir}/run.txt" | myecho echo ------------------------------------------------------------------ echo "2." echo "Running with root-module modb" -echo " java --module-path mlib --module modb/pkgb.BMain" +echo " java --module-path target --module modb/pkgb.BMain" "${JAVA_HOME}/bin/java" --module-path mlib --module modb/pkgb.BMain 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho echo ------------------------------------------------------------------ echo "3." echo "Running with root-module modc" -echo " java --module-path mlib --module modc/pkgc.CMain" +echo " java --module-path target --module modc/pkgc.CMain" "${JAVA_HOME}/bin/java" --module-path mlib --module modc/pkgc.CMain 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho echo ------------------------------------------------------------------ echo "4." echo "Running with root-module modb plus --add-modules modc" -echo " java --module-path mlib --add-modules modc --module modb/pkgb.BMain" +echo " java --module-path target --add-modules modc --module modb/pkgb.BMain" "${JAVA_HOME}/bin/java" --module-path mlib --add-modules modc --module modb/pkgb.BMain 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho echo ------------------------------------------------------------------ echo "5." echo "Running with root-module modb plus automatic module javax.json" -echo " java --module-path mlib${PATH_SEPARATOR}../amlib --module modb/pkgb.BMain" +echo " java --module-path target${PATH_SEPARATOR}../amlib --module modb/pkgb.BMain" "${JAVA_HOME}/bin/java" --module-path "mlib${PATH_SEPARATOR}../amlib" --module modb/pkgb.BMain 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho echo ------------------------------------------------------------------ echo "6." echo "Running with root-module modb plus limitmods" -echo " java --module-path mlib --limit-modules modb --module modb/pkgb.BMain" +echo " java --module-path target --limit-modules modb --module modb/pkgb.BMain" "${JAVA_HOME}/bin/java" --module-path mlib --limit-modules modb --module modb/pkgb.BMain 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho echo ------------------------------------------------------------------ @@ -72,7 +72,7 @@ echo "Running with root-module modb plus limitmods on module java.logging and ja echo "- Note that modb must be added to limitmods otherwise moda cannot be resolved" echo " (adding only moda would work too, but would be inconventient when modb has" echo " many requires)" -echo " java --module-path mlib -limitmods java.logging,java.scripting,modb --module modb/pkgb.BMain" +echo " java --module-path target -limitmods java.logging,java.scripting,modb --module modb/pkgb.BMain" "${JAVA_HOME}/bin/java" --module-path mlib --limit-modules java.logging,java.scripting,modb --module modb/pkgb.BMain 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho echo ------------------------------------------------------------------ @@ -86,7 +86,7 @@ echo "Linking with root module modb ..." JAVA_HOME_OS="${JAVA_HOME}" # /x/ doesn't work on module path on windows, replace with x: (echo "${OSTYPE}" | grep -i win >/dev/null) && JAVA_HOME_OS=$(echo "${JAVA_HOME}" | sed -r 's|^/([a-z])/|\1:/|') -echo " jlink --module-path mlib${PATH_SEPARATOR}${JAVA_HOME_OS}/jmods --add-modules modb --output jimage/modb" +echo " jlink --module-path target${PATH_SEPARATOR}${JAVA_HOME_OS}/jmods --add-modules modb --output jimage/modb" rm -rf ./jimage # TODO The following seems to work (on JDK 11) only with the `-v` option (otherwise `jlink` fails silently) "${JAVA_HOME}/bin/jlink" -v --module-path "mlib${PATH_SEPARATOR}${JAVA_HOME_OS}/jmods" --add-modules modb --output jimage/modb 2>&1 | normalize_jlink "${JAVA_HOME_OS}" | tee -a "${result_dir}/run.txt" | myecho diff --git a/jigsaw-examples/example_resources/README.adoc b/jigsaw-examples/example_resources/README.adoc index 00f8b153..9b8e3a59 100644 --- a/jigsaw-examples/example_resources/README.adoc +++ b/jigsaw-examples/example_resources/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -67,7 +67,52 @@ include::m4/run-result/run.txt[] [[sec:maven-4-migration]] == Maven 4 Migration -This example was migrated to Maven 4 using the standard approach documented in the xref:../../README.adoc#maven-4-migration[central Maven 4 Migration guide]. +This example was migrated to Maven 4 with a special source tree structure to properly separate Java source files from resources, following Maven conventions. -The source files follow the standard Module Source Hierarchy setup. -Resource handling required explicit configuration of `maven-resources-plugin` to copy `.properties` files from the modular source directories to the target classes directories, as the hybrid compilation approach only packages compiled `.class` files by default. \ No newline at end of file +The `m4/src` directory follows proper Maven directory conventions with separate `java/` and `resources/` subdirectories: + +[source] +---- +m4/src/ +├── modb/main/ +│ ├── java/ # Java source files only +│ │ ├── module-info.java +│ │ ├── pkgb/B.java +│ │ └── pkgbinternal/BInternal.java +│ └── resources/ # Resource files only +│ ├── pkgb/b.properties +│ ├── pkgbinternal/binternal.properties +│ └── resources.modb/resources.properties +├── modc/main/ +│ ├── java/ # Java source files only +│ │ ├── module-info.java +│ │ ├── pkgc/C.java +│ │ └── pkgcinternal/CInternal.java +│ └── resources/ # Resource files only +│ ├── cnopackage.properties +│ ├── pkgc/c.properties +│ ├── pkgcinternal/cinternal.properties +│ └── resources.modc/resources.properties +└── modmain/main/ + └── java/ # Java source files only (no resources) + ├── module-info.java + ├── pkgmain/Main.java + └── pkgmaininternal/IdGen.java +---- + +This structure differs from the original `src/` directory where Java and resource files coexist in the same package directories. +The Maven build properly handles resources through explicit `maven-resources-plugin` configuration that copies resource files from `src//main/resources` to `target/classes/`. + +[CAUTION] +.Why Source Files Are Copied, Not Symlinked +==== +Unlike other examples where we use symbolic links to reference the original `src/` directory, this example requires _full copies_ of all source files in `m4/src/`. + +The Java compiler cannot properly resolve module structure when individual source files are symlinked from locations outside the module source path. +When using `--module-source-path`, `javac` expects all files of a module to reside within a single directory tree and fails with "module not found on module source path" errors when encountering symlinks pointing outside that tree. + +Therefore, `m4/src/` contains actual file copies of all Java sources and resources from the original `src/` directory, reorganized into Maven's standard directory structure. + +To ensure consistency between the original sources and the Maven 4 copies, the `m4/verify-sources.sh` script validates that all files are identical despite the different directory layouts. +This script runs automatically as part of `m4/verify.sh`. +==== \ No newline at end of file diff --git a/jigsaw-examples/example_resources/m4/.gitignore b/jigsaw-examples/example_resources/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_resources/m4/.gitignore +++ b/jigsaw-examples/example_resources/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_resources/m4/clean.sh b/jigsaw-examples/example_resources/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_resources/m4/clean.sh +++ b/jigsaw-examples/example_resources/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_resources/m4/compile.sh b/jigsaw-examples/example_resources/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_resources/m4/compile.sh +++ b/jigsaw-examples/example_resources/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_resources/m4/pom.xml b/jigsaw-examples/example_resources/m4/pom.xml index 6352ab95..23b4567a 100644 --- a/jigsaw-examples/example_resources/m4/pom.xml +++ b/jigsaw-examples/example_resources/m4/pom.xml @@ -18,15 +18,12 @@ modb - src/modb/main/java modc - src/modc/main/java modmain - src/modmain/main/java @@ -52,14 +49,7 @@ ${project.build.directory}/classes/modb - src/modb/main/java - - **/*.properties - **/*.txt - - - **/*.java - + src/modb/main/resources @@ -74,38 +64,55 @@ ${project.build.directory}/classes/modc - src/modc/main/java - - **/*.properties - **/*.txt - - - **/*.java - + src/modc/main/resources + + + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + - copy-modmain-resources - process-resources + default-jar + none + + + + modb + package - copy-resources + jar - ${project.build.directory}/classes/modmain - - - src/modmain/main/java - - **/*.properties - **/*.txt - - - **/*.java - - - + ${project.build.outputDirectory}/modb + modb + + + + modc + package + + jar + + + ${project.build.outputDirectory}/modc + modc + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain diff --git a/jigsaw-examples/example_resources/m4/run.sh b/jigsaw-examples/example_resources/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_resources/m4/run.sh +++ b/jigsaw-examples/example_resources/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_resources/m4/src/modb/main/java b/jigsaw-examples/example_resources/m4/src/modb/main/java deleted file mode 120000 index 7eb53275..00000000 --- a/jigsaw-examples/example_resources/m4/src/modb/main/java +++ /dev/null @@ -1 +0,0 @@ -../../../../src/modb \ No newline at end of file diff --git a/jigsaw-examples/example_resources/m4/src/modb/main/java/module-info.java b/jigsaw-examples/example_resources/m4/src/modb/main/java/module-info.java new file mode 100644 index 00000000..16115023 --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modb/main/java/module-info.java @@ -0,0 +1,6 @@ +module modb { + requires transitive modc; + + exports pkgb; + opens pkgb; +} diff --git a/jigsaw-examples/example_resources/m4/src/modb/main/java/pkgb/B.java b/jigsaw-examples/example_resources/m4/src/modb/main/java/pkgb/B.java new file mode 100644 index 00000000..c8a06fbe --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modb/main/java/pkgb/B.java @@ -0,0 +1,46 @@ +package pkgb; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import pkgc.*; + +public class B { + public String doIt() { + return "from B"; + } + + public C getMyC() { + return new C(); + } + + // access resources in modb + public String getTextFromProperties() throws IOException { + String resourceFileName = "/resources.modb/resources.properties"; // now we get modb's resources.properties + + final Properties properties = new Properties(); + try (final InputStream stream = B.class.getModule().getResourceAsStream(resourceFileName)) { + properties.load(stream); + } + return properties.getProperty("text", "modb's resources properties not found in modb"); + } + + // access resources in modc (from modb) + public String getTextFromMODCsProperties() throws IOException { + String resourceFileName = "/pkgc/c.properties"; // The resource path must be resolveable as a package name *and* this package has to be open (see modc's module-info.java) + // Note that just an export on this package name is not sufficient for access! + + final Properties properties = new Properties(); + try (final InputStream stream = C.class.getModule().getResourceAsStream(resourceFileName)) { + properties.load(stream); + } + String propertyFromMODC = properties.getProperty("text"); + if (propertyFromMODC == null) { + return "modc's resources properties not found via modb"; + } + else { + return propertyFromMODC + " - but retrieved via modb!"; + } + } +} diff --git a/jigsaw-examples/example_resources/m4/src/modb/main/java/pkgbinternal/BInternal.java b/jigsaw-examples/example_resources/m4/src/modb/main/java/pkgbinternal/BInternal.java new file mode 100644 index 00000000..e6fbc0b4 --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modb/main/java/pkgbinternal/BInternal.java @@ -0,0 +1,5 @@ +package pkgbinternal; + +public class BInternal { +// does not do anything - just there to ensure that there is an package pkgbinternal +} diff --git a/jigsaw-examples/example_resources/m4/src/modb/main/resources/pkgb/b.properties b/jigsaw-examples/example_resources/m4/src/modb/main/resources/pkgb/b.properties new file mode 100644 index 00000000..8f9a497f --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modb/main/resources/pkgb/b.properties @@ -0,0 +1,2 @@ +# Can only be accessed from outside modb, if package pkgb is open'ed in modb's module-info +text=Hello World, from modb's b.properties (whose package is opened) diff --git a/jigsaw-examples/example_resources/m4/src/modb/main/resources/pkgbinternal/binternal.properties b/jigsaw-examples/example_resources/m4/src/modb/main/resources/pkgbinternal/binternal.properties new file mode 100644 index 00000000..0a18c4a9 --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modb/main/resources/pkgbinternal/binternal.properties @@ -0,0 +1,2 @@ +# Can only be accessed from outside modb, if package pkgbinternal would be open'ed in modb's module-info +text=Hello World, from modb's binternal.properties (whose package is not opened) \ No newline at end of file diff --git a/jigsaw-examples/example_resources/m4/src/modb/main/resources/resources.modb/resources.properties b/jigsaw-examples/example_resources/m4/src/modb/main/resources/resources.modb/resources.properties new file mode 100644 index 00000000..eb42fd66 --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modb/main/resources/resources.modb/resources.properties @@ -0,0 +1,2 @@ +# Can only be accessed from outside modb, if package resources.modb would be open'ed in modb's module-info +text=Hello World, from modb's resources.properties \ No newline at end of file diff --git a/jigsaw-examples/example_resources/m4/src/modc/main/java b/jigsaw-examples/example_resources/m4/src/modc/main/java deleted file mode 120000 index 0acd5eeb..00000000 --- a/jigsaw-examples/example_resources/m4/src/modc/main/java +++ /dev/null @@ -1 +0,0 @@ -../../../../src/modc \ No newline at end of file diff --git a/jigsaw-examples/example_resources/m4/src/modc/main/java/module-info.java b/jigsaw-examples/example_resources/m4/src/modc/main/java/module-info.java new file mode 100644 index 00000000..424f99db --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modc/main/java/module-info.java @@ -0,0 +1,4 @@ +module modc { + exports pkgc; + opens pkgc; +} diff --git a/jigsaw-examples/example_resources/m4/src/modc/main/java/pkgc/C.java b/jigsaw-examples/example_resources/m4/src/modc/main/java/pkgc/C.java new file mode 100644 index 00000000..7da97484 --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modc/main/java/pkgc/C.java @@ -0,0 +1,21 @@ +package pkgc; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class C { + public String doIt() { + return "from C"; + } + + // access resources in modc! + public String getTextFromProperties() throws IOException { + final Properties properties = new Properties(); + try (final InputStream stream = this.getClass().getResourceAsStream("/resources.modc/resources.properties")) { + properties.load(stream); + } + + return properties.getProperty("text", "not found"); + } +} diff --git a/jigsaw-examples/example_resources/m4/src/modc/main/java/pkgcinternal/CInternal.java b/jigsaw-examples/example_resources/m4/src/modc/main/java/pkgcinternal/CInternal.java new file mode 100644 index 00000000..06c1020b --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modc/main/java/pkgcinternal/CInternal.java @@ -0,0 +1,5 @@ +package pkgcinternal; + +public class CInternal { +// does not do anything - just there to ensure that there is an package pkgcinternal +} diff --git a/jigsaw-examples/example_resources/m4/src/modc/main/resources/cnopackage.properties b/jigsaw-examples/example_resources/m4/src/modc/main/resources/cnopackage.properties new file mode 100644 index 00000000..3358415e --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modc/main/resources/cnopackage.properties @@ -0,0 +1,2 @@ +# Can always be accessed from outside modc, because this resource file is in the unnamed package +text=Hello World, from modc's cnopackage.properties (whose unnamed package is always not encapsulated) \ No newline at end of file diff --git a/jigsaw-examples/example_resources/m4/src/modc/main/resources/pkgc/c.properties b/jigsaw-examples/example_resources/m4/src/modc/main/resources/pkgc/c.properties new file mode 100644 index 00000000..12e3c333 --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modc/main/resources/pkgc/c.properties @@ -0,0 +1,2 @@ +# Can only be accessed from outside modc, if package pkgc is open'ed in modb's module-info +text=Hello World, from modc's c.properties (whose package is opened) \ No newline at end of file diff --git a/jigsaw-examples/example_resources/m4/src/modc/main/resources/pkgcinternal/cinternal.properties b/jigsaw-examples/example_resources/m4/src/modc/main/resources/pkgcinternal/cinternal.properties new file mode 100644 index 00000000..733aa360 --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modc/main/resources/pkgcinternal/cinternal.properties @@ -0,0 +1,2 @@ +# Can only be accessed from outside modc, if package pkgcinternal would be open'ed in modb's module-info +text=Hello World, from modc's cinternal.properties (whose package is not opened) \ No newline at end of file diff --git a/jigsaw-examples/example_resources/m4/src/modc/main/resources/resources.modc/resources.properties b/jigsaw-examples/example_resources/m4/src/modc/main/resources/resources.modc/resources.properties new file mode 100644 index 00000000..6a5400da --- /dev/null +++ b/jigsaw-examples/example_resources/m4/src/modc/main/resources/resources.modc/resources.properties @@ -0,0 +1,2 @@ +# Can only be accessed from outside modc, if package resources.modc would be open'ed in modb's module-info +text=Hello World, from modc's resources.properties \ No newline at end of file diff --git a/jigsaw-examples/example_resources/m4/verify-sources.sh b/jigsaw-examples/example_resources/m4/verify-sources.sh new file mode 100755 index 00000000..f4b97f2a --- /dev/null +++ b/jigsaw-examples/example_resources/m4/verify-sources.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +echo "=== Verifying source file consistency between ../src and m4/src ===" +echo + +# Track if any differences found +DIFFERENCES_FOUND=0 + +# Find all files in ../src (excluding .gitignore) +while IFS= read -r -d '' srcfile; do + # Get relative path from ../src + relpath="${srcfile#../src/}" + + # Extract module name (first directory component) + module="${relpath%%/*}" + + # Get path after module name + pathInModule="${relpath#*/}" + + # Determine if it's a Java file or resource file + if [[ "${pathInModule}" == *.java ]]; then + # Java file: should be in src/{module}/main/java/{path} + m4file="src/${module}/main/java/${pathInModule}" + else + # Resource file: should be in src/{module}/main/resources/{path} + m4file="src/${module}/main/resources/${pathInModule}" + fi + + # Check if m4 file exists + if [[ ! -f "${m4file}" ]]; then + echo "ERROR: Missing file in m4/src: ${m4file}" + echo " Expected from: ${srcfile}" + DIFFERENCES_FOUND=1 + continue + fi + + # Compare file contents + if ! diff -q "${srcfile}" "${m4file}" > /dev/null 2>&1; then + echo "ERROR: File content differs:" + echo " Source: ${srcfile}" + echo " M4: ${m4file}" + echo " Diff:" + diff -u "${srcfile}" "${m4file}" | head -20 + DIFFERENCES_FOUND=1 + fi +done < <(find ../src -type f ! -name '.gitignore' -print0) + +# Check for extra files in m4/src that don't exist in ../src +while IFS= read -r -d '' m4file; do + # Get relative path from src/ + relpath="${m4file#src/}" + + # Extract module name and determine original structure + if [[ "${relpath}" =~ ^([^/]+)/main/java/(.+)$ ]]; then + module="${BASH_REMATCH[1]}" + pathInModule="${BASH_REMATCH[2]}" + srcfile="../src/${module}/${pathInModule}" + elif [[ "${relpath}" =~ ^([^/]+)/main/resources/(.+)$ ]]; then + module="${BASH_REMATCH[1]}" + pathInModule="${BASH_REMATCH[2]}" + srcfile="../src/${module}/${pathInModule}" + else + echo "WARNING: Unexpected file structure: ${m4file}" + continue + fi + + # Check if source file exists + if [[ ! -f "${srcfile}" ]]; then + echo "ERROR: Extra file in m4/src not present in ../src:" + echo " M4: ${m4file}" + echo " Source: ${srcfile} (expected but not found)" + DIFFERENCES_FOUND=1 + fi +done < <(find src -type f ! -name '.gitignore' -print0) + +echo +if [[ ${DIFFERENCES_FOUND} -eq 0 ]]; then + echo "✅ All source files are consistent between ../src and m4/src" + exit 0 +else + echo "❌ Differences found between ../src and m4/src" + exit 1 +fi diff --git a/jigsaw-examples/example_resources/m4/verify.sh b/jigsaw-examples/example_resources/m4/verify.sh index 9ab32b47..361bf764 100755 --- a/jigsaw-examples/example_resources/m4/verify.sh +++ b/jigsaw-examples/example_resources/m4/verify.sh @@ -14,6 +14,11 @@ fi echo "=== Verifying ${EXAMPLE_NAME} (Maven 4) ===" echo +# Step 0: Verify source file consistency +echo "Step 0: Verify source file consistency" +./verify-sources.sh +echo + # Check if expected result exists if [ ! -f "${EXPECTED}" ]; then echo "❌ ERROR: Expected result not found at ${EXPECTED}" diff --git a/jigsaw-examples/example_resources/src/modb/module-info.java b/jigsaw-examples/example_resources/src/modb/module-info.java index a5fde7db..16115023 100644 --- a/jigsaw-examples/example_resources/src/modb/module-info.java +++ b/jigsaw-examples/example_resources/src/modb/module-info.java @@ -1,6 +1,6 @@ -module modb { - requires transitive modc; - - exports pkgb; - opens pkgb; -} +module modb { + requires transitive modc; + + exports pkgb; + opens pkgb; +} diff --git a/jigsaw-examples/example_resources/src/modb/pkgb/B.java b/jigsaw-examples/example_resources/src/modb/pkgb/B.java index 98f532e1..c8a06fbe 100644 --- a/jigsaw-examples/example_resources/src/modb/pkgb/B.java +++ b/jigsaw-examples/example_resources/src/modb/pkgb/B.java @@ -1,46 +1,46 @@ -package pkgb; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import pkgc.*; - -public class B { - public String doIt() { - return "from B"; - } - - public C getMyC() { - return new C(); - } - - // access resources in modb - public String getTextFromProperties() throws IOException { - String resourceFileName = "/resources.modb/resources.properties"; // now we get modb's resources.properties - - final Properties properties = new Properties(); - try (final InputStream stream = B.class.getModule().getResourceAsStream(resourceFileName)) { - properties.load(stream); - } - return properties.getProperty("text", "modb's resources properties not found in modb"); - } - - // access resources in modc (from modb) - public String getTextFromMODCsProperties() throws IOException { - String resourceFileName = "/pkgc/c.properties"; // The resource path must be resolveable as a package name *and* this package has to be open (see modc's module-info.java) - // Note that just an export on this package name is not sufficient for access! - - final Properties properties = new Properties(); - try (final InputStream stream = C.class.getModule().getResourceAsStream(resourceFileName)) { - properties.load(stream); - } - String propertyFromMODC = properties.getProperty("text"); - if (propertyFromMODC == null) { - return "modc's resources properties not found via modb"; - } - else { - return propertyFromMODC + " - but retrieved via modb!"; - } - } -} +package pkgb; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import pkgc.*; + +public class B { + public String doIt() { + return "from B"; + } + + public C getMyC() { + return new C(); + } + + // access resources in modb + public String getTextFromProperties() throws IOException { + String resourceFileName = "/resources.modb/resources.properties"; // now we get modb's resources.properties + + final Properties properties = new Properties(); + try (final InputStream stream = B.class.getModule().getResourceAsStream(resourceFileName)) { + properties.load(stream); + } + return properties.getProperty("text", "modb's resources properties not found in modb"); + } + + // access resources in modc (from modb) + public String getTextFromMODCsProperties() throws IOException { + String resourceFileName = "/pkgc/c.properties"; // The resource path must be resolveable as a package name *and* this package has to be open (see modc's module-info.java) + // Note that just an export on this package name is not sufficient for access! + + final Properties properties = new Properties(); + try (final InputStream stream = C.class.getModule().getResourceAsStream(resourceFileName)) { + properties.load(stream); + } + String propertyFromMODC = properties.getProperty("text"); + if (propertyFromMODC == null) { + return "modc's resources properties not found via modb"; + } + else { + return propertyFromMODC + " - but retrieved via modb!"; + } + } +} diff --git a/jigsaw-examples/example_resources/src/modb/pkgb/b.properties b/jigsaw-examples/example_resources/src/modb/pkgb/b.properties index c0e3d3fd..8f9a497f 100644 --- a/jigsaw-examples/example_resources/src/modb/pkgb/b.properties +++ b/jigsaw-examples/example_resources/src/modb/pkgb/b.properties @@ -1,2 +1,2 @@ -# Can only be accessed from outside modb, if package pkgb is open'ed in modb's module-info -text=Hello World, from modb's b.properties (whose package is opened) +# Can only be accessed from outside modb, if package pkgb is open'ed in modb's module-info +text=Hello World, from modb's b.properties (whose package is opened) diff --git a/jigsaw-examples/example_resources/src/modb/pkgbinternal/BInternal.java b/jigsaw-examples/example_resources/src/modb/pkgbinternal/BInternal.java index 7fc2a83e..e6fbc0b4 100644 --- a/jigsaw-examples/example_resources/src/modb/pkgbinternal/BInternal.java +++ b/jigsaw-examples/example_resources/src/modb/pkgbinternal/BInternal.java @@ -1,5 +1,5 @@ -package pkgbinternal; - -public class BInternal { -// does not do anything - just there to ensure that there is an package pkgbinternal -} +package pkgbinternal; + +public class BInternal { +// does not do anything - just there to ensure that there is an package pkgbinternal +} diff --git a/jigsaw-examples/example_resources/src/modb/pkgbinternal/binternal.properties b/jigsaw-examples/example_resources/src/modb/pkgbinternal/binternal.properties index 4d0be75d..0a18c4a9 100644 --- a/jigsaw-examples/example_resources/src/modb/pkgbinternal/binternal.properties +++ b/jigsaw-examples/example_resources/src/modb/pkgbinternal/binternal.properties @@ -1,2 +1,2 @@ -# Can only be accessed from outside modb, if package pkgbinternal would be open'ed in modb's module-info +# Can only be accessed from outside modb, if package pkgbinternal would be open'ed in modb's module-info text=Hello World, from modb's binternal.properties (whose package is not opened) \ No newline at end of file diff --git a/jigsaw-examples/example_resources/src/modb/resources.modb/resources.properties b/jigsaw-examples/example_resources/src/modb/resources.modb/resources.properties index f888bcbe..eb42fd66 100644 --- a/jigsaw-examples/example_resources/src/modb/resources.modb/resources.properties +++ b/jigsaw-examples/example_resources/src/modb/resources.modb/resources.properties @@ -1,2 +1,2 @@ -# Can only be accessed from outside modb, if package resources.modb would be open'ed in modb's module-info +# Can only be accessed from outside modb, if package resources.modb would be open'ed in modb's module-info text=Hello World, from modb's resources.properties \ No newline at end of file diff --git a/jigsaw-examples/example_resources/src/modc/cnopackage.properties b/jigsaw-examples/example_resources/src/modc/cnopackage.properties index 5565149f..3358415e 100644 --- a/jigsaw-examples/example_resources/src/modc/cnopackage.properties +++ b/jigsaw-examples/example_resources/src/modc/cnopackage.properties @@ -1,2 +1,2 @@ -# Can always be accessed from outside modc, because this resource file is in the unnamed package +# Can always be accessed from outside modc, because this resource file is in the unnamed package text=Hello World, from modc's cnopackage.properties (whose unnamed package is always not encapsulated) \ No newline at end of file diff --git a/jigsaw-examples/example_resources/src/modc/module-info.java b/jigsaw-examples/example_resources/src/modc/module-info.java index 894d278f..424f99db 100644 --- a/jigsaw-examples/example_resources/src/modc/module-info.java +++ b/jigsaw-examples/example_resources/src/modc/module-info.java @@ -1,4 +1,4 @@ -module modc { - exports pkgc; - opens pkgc; -} +module modc { + exports pkgc; + opens pkgc; +} diff --git a/jigsaw-examples/example_resources/src/modc/pkgc/C.java b/jigsaw-examples/example_resources/src/modc/pkgc/C.java index ace3ac31..7da97484 100644 --- a/jigsaw-examples/example_resources/src/modc/pkgc/C.java +++ b/jigsaw-examples/example_resources/src/modc/pkgc/C.java @@ -1,21 +1,21 @@ -package pkgc; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -public class C { - public String doIt() { - return "from C"; - } - - // access resources in modc! - public String getTextFromProperties() throws IOException { - final Properties properties = new Properties(); - try (final InputStream stream = this.getClass().getResourceAsStream("/resources.modc/resources.properties")) { - properties.load(stream); - } - - return properties.getProperty("text", "not found"); - } -} +package pkgc; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class C { + public String doIt() { + return "from C"; + } + + // access resources in modc! + public String getTextFromProperties() throws IOException { + final Properties properties = new Properties(); + try (final InputStream stream = this.getClass().getResourceAsStream("/resources.modc/resources.properties")) { + properties.load(stream); + } + + return properties.getProperty("text", "not found"); + } +} diff --git a/jigsaw-examples/example_resources/src/modc/pkgc/c.properties b/jigsaw-examples/example_resources/src/modc/pkgc/c.properties index be0b8ccf..12e3c333 100644 --- a/jigsaw-examples/example_resources/src/modc/pkgc/c.properties +++ b/jigsaw-examples/example_resources/src/modc/pkgc/c.properties @@ -1,2 +1,2 @@ -# Can only be accessed from outside modc, if package pkgc is open'ed in modb's module-info +# Can only be accessed from outside modc, if package pkgc is open'ed in modb's module-info text=Hello World, from modc's c.properties (whose package is opened) \ No newline at end of file diff --git a/jigsaw-examples/example_resources/src/modc/pkgcinternal/CInternal.java b/jigsaw-examples/example_resources/src/modc/pkgcinternal/CInternal.java index 51535b0a..06c1020b 100644 --- a/jigsaw-examples/example_resources/src/modc/pkgcinternal/CInternal.java +++ b/jigsaw-examples/example_resources/src/modc/pkgcinternal/CInternal.java @@ -1,5 +1,5 @@ -package pkgcinternal; - -public class CInternal { -// does not do anything - just there to ensure that there is an package pkgcinternal -} +package pkgcinternal; + +public class CInternal { +// does not do anything - just there to ensure that there is an package pkgcinternal +} diff --git a/jigsaw-examples/example_resources/src/modc/pkgcinternal/cinternal.properties b/jigsaw-examples/example_resources/src/modc/pkgcinternal/cinternal.properties index e4aa68d9..733aa360 100644 --- a/jigsaw-examples/example_resources/src/modc/pkgcinternal/cinternal.properties +++ b/jigsaw-examples/example_resources/src/modc/pkgcinternal/cinternal.properties @@ -1,2 +1,2 @@ -# Can only be accessed from outside modc, if package pkgcinternal would be open'ed in modb's module-info +# Can only be accessed from outside modc, if package pkgcinternal would be open'ed in modb's module-info text=Hello World, from modc's cinternal.properties (whose package is not opened) \ No newline at end of file diff --git a/jigsaw-examples/example_resources/src/modc/resources.modc/resources.properties b/jigsaw-examples/example_resources/src/modc/resources.modc/resources.properties index cc337758..6a5400da 100644 --- a/jigsaw-examples/example_resources/src/modc/resources.modc/resources.properties +++ b/jigsaw-examples/example_resources/src/modc/resources.modc/resources.properties @@ -1,2 +1,2 @@ -# Can only be accessed from outside modc, if package resources.modc would be open'ed in modb's module-info +# Can only be accessed from outside modc, if package resources.modc would be open'ed in modb's module-info text=Hello World, from modc's resources.properties \ No newline at end of file diff --git a/jigsaw-examples/example_resources/src/modmain/module-info.java b/jigsaw-examples/example_resources/src/modmain/module-info.java index 082e392f..9628224f 100644 --- a/jigsaw-examples/example_resources/src/modmain/module-info.java +++ b/jigsaw-examples/example_resources/src/modmain/module-info.java @@ -1,3 +1,3 @@ -open module modmain { // allow reflective access, currently used in the example_jerry-mouse - requires modb; -} +open module modmain { // allow reflective access, currently used in the example_jerry-mouse + requires modb; +} diff --git a/jigsaw-examples/example_resources/src/modmain/pkgmain/Main.java b/jigsaw-examples/example_resources/src/modmain/pkgmain/Main.java index 8b0867ee..fbb548dd 100644 --- a/jigsaw-examples/example_resources/src/modmain/pkgmain/Main.java +++ b/jigsaw-examples/example_resources/src/modmain/pkgmain/Main.java @@ -1,74 +1,74 @@ -package pkgmain; - -import java.io.InputStream; -import java.util.Properties; -import java.io.IOException; - -import pkgb.B; -import pkgc.C; -import pkgmaininternal.IdGen; - -public class Main { - private String id; - - public Main() { - id = IdGen.createID(); - } - - public static void main(String[] args) throws IOException { - Main mymain = new Main(); - B myb = new B(); - - C myc = myb.getMyC(); - System.out.println("Main: " + mymain.toString() + ", B: " + myb.doIt() + ", C: " + myc.doIt()); - - System.out.println("B: Get text from modb's properties: " + myb.getTextFromProperties()); - System.out.println("C: Get text from modc's properties: " + myc.getTextFromProperties()); - - // ------------------------------------------------------------------------------------------------------------ - - // works, as resources.properties in modc is not encapsulated (because its location is not a package) - - System.out.println("B: Get text from modc's properties: " + myb.getTextFromMODCsProperties()); - - // ------------------------------------------------------------------------------------------------------------ - - System.out.println("Main: Get text from modb's /pkgb/b.properties , whose package is opened: " + getTextFromMODBProperties("/pkgb/b.properties")); - System.out.println("Main: Get text from modb's /pkgbinternal/binternal.properties , whose package is not opened: " + getTextFromMODBProperties("/pkgbinternal/pbinternal.properties")); - - System.out.println("Main: Get text from modc's /pkgc/c.properties , whose package is opened: " + getTextFromMODCProperties("/pkgc/c.properties")); - System.out.println("Main: Get text from modc's /pkgcinternal/cinternal.properties , whose package is not opened: " + getTextFromMODCProperties("/pkgcinternal/cinternal.properties")); - System.out.println("Main: Get text from modc's /cnopackage.properties , whose package is in the unnamed package: " + getTextFromMODCProperties("/cnopackage.properties")); - } - - public static String getTextFromMODBProperties(String resourceFileName) throws IOException { - final Properties properties = new Properties(); - try (final InputStream stream = B.class.getModule().getResourceAsStream(resourceFileName)) { - try { - properties.load(stream); - return properties.getProperty("text", "modb's " + resourceFileName + " not found in modmain"); - } - catch (NullPointerException npex) { - return "ERROR: Cannot be loaded"; - } - } - } - - public static String getTextFromMODCProperties(String resourceFileName) throws IOException { - final Properties properties = new Properties(); - try (final InputStream stream = C.class.getModule().getResourceAsStream(resourceFileName)) { - try { - properties.load(stream); - return properties.getProperty("text", "modc's " + resourceFileName + " not found in modmain"); - } - catch (NullPointerException npex) { - return "ERROR: Cannot be loaded"; - } - } - } - - @Override - public String toString() { - return this.getClass().getName() + ", id=" + id; - } -} +package pkgmain; + +import java.io.InputStream; +import java.util.Properties; +import java.io.IOException; + +import pkgb.B; +import pkgc.C; +import pkgmaininternal.IdGen; + +public class Main { + private String id; + + public Main() { + id = IdGen.createID(); + } + + public static void main(String[] args) throws IOException { + Main mymain = new Main(); + B myb = new B(); + + C myc = myb.getMyC(); + System.out.println("Main: " + mymain.toString() + ", B: " + myb.doIt() + ", C: " + myc.doIt()); + + System.out.println("B: Get text from modb's properties: " + myb.getTextFromProperties()); + System.out.println("C: Get text from modc's properties: " + myc.getTextFromProperties()); + + // ------------------------------------------------------------------------------------------------------------ + + // works, as resources.properties in modc is not encapsulated (because its location is not a package) + + System.out.println("B: Get text from modc's properties: " + myb.getTextFromMODCsProperties()); + + // ------------------------------------------------------------------------------------------------------------ + + System.out.println("Main: Get text from modb's /pkgb/b.properties , whose package is opened: " + getTextFromMODBProperties("/pkgb/b.properties")); + System.out.println("Main: Get text from modb's /pkgbinternal/binternal.properties , whose package is not opened: " + getTextFromMODBProperties("/pkgbinternal/pbinternal.properties")); + + System.out.println("Main: Get text from modc's /pkgc/c.properties , whose package is opened: " + getTextFromMODCProperties("/pkgc/c.properties")); + System.out.println("Main: Get text from modc's /pkgcinternal/cinternal.properties , whose package is not opened: " + getTextFromMODCProperties("/pkgcinternal/cinternal.properties")); + System.out.println("Main: Get text from modc's /cnopackage.properties , whose package is in the unnamed package: " + getTextFromMODCProperties("/cnopackage.properties")); + } + + public static String getTextFromMODBProperties(String resourceFileName) throws IOException { + final Properties properties = new Properties(); + try (final InputStream stream = B.class.getModule().getResourceAsStream(resourceFileName)) { + try { + properties.load(stream); + return properties.getProperty("text", "modb's " + resourceFileName + " not found in modmain"); + } + catch (NullPointerException npex) { + return "ERROR: Cannot be loaded"; + } + } + } + + public static String getTextFromMODCProperties(String resourceFileName) throws IOException { + final Properties properties = new Properties(); + try (final InputStream stream = C.class.getModule().getResourceAsStream(resourceFileName)) { + try { + properties.load(stream); + return properties.getProperty("text", "modc's " + resourceFileName + " not found in modmain"); + } + catch (NullPointerException npex) { + return "ERROR: Cannot be loaded"; + } + } + } + + @Override + public String toString() { + return this.getClass().getName() + ", id=" + id; + } +} diff --git a/jigsaw-examples/example_splitpackage/README.adoc b/jigsaw-examples/example_splitpackage/README.adoc index 1275e16f..bab45b55 100644 --- a/jigsaw-examples/example_splitpackage/README.adoc +++ b/jigsaw-examples/example_splitpackage/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -66,7 +66,7 @@ The migration demonstrates an important constraint of the split package problem. * `modsplitbar2` - Second module with package `pkgbar` The foo modules (`modmainfoo`, `modsplitfoo1`, `modsplitfoo2`) _cannot_ be compiled because `modmainfoo` requires both `modsplitfoo1` and `modsplitfoo2`, which both export package `pkgfoo`. -This violates JPMS rules at compile time. +This violates Java Module rules at compile time. ==== Golden Master Testing diff --git a/jigsaw-examples/example_splitpackage/m4/.gitignore b/jigsaw-examples/example_splitpackage/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_splitpackage/m4/.gitignore +++ b/jigsaw-examples/example_splitpackage/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_splitpackage/m4/clean.sh b/jigsaw-examples/example_splitpackage/m4/clean.sh index 98d7b2fb..8206b8d3 100755 --- a/jigsaw-examples/example_splitpackage/m4/clean.sh +++ b/jigsaw-examples/example_splitpackage/m4/clean.sh @@ -2,5 +2,4 @@ set -eu -o pipefail rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_splitpackage/m4/compile.sh b/jigsaw-examples/example_splitpackage/m4/compile.sh index c17afba1..5a8ae38d 100755 --- a/jigsaw-examples/example_splitpackage/m4/compile.sh +++ b/jigsaw-examples/example_splitpackage/m4/compile.sh @@ -20,24 +20,13 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_splitpackage/m4/pom.xml b/jigsaw-examples/example_splitpackage/m4/pom.xml index 6ccdcdb3..f6a12faa 100644 --- a/jigsaw-examples/example_splitpackage/m4/pom.xml +++ b/jigsaw-examples/example_splitpackage/m4/pom.xml @@ -19,15 +19,12 @@ modmainbar - src/modmainbar/main/java modsplitbar1 - src/modsplitbar1/main/java modsplitbar2 - src/modsplitbar2/main/java @@ -37,6 +34,52 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmainbar + package + + jar + + + ${project.build.outputDirectory}/modmainbar + modmainbar + + + + modsplitbar1 + package + + jar + + + ${project.build.outputDirectory}/modsplitbar1 + modsplitbar1 + + + + modsplitbar2 + package + + jar + + + ${project.build.outputDirectory}/modsplitbar2 + modsplitbar2 + + + + diff --git a/jigsaw-examples/example_splitpackage/m4/run.sh b/jigsaw-examples/example_splitpackage/m4/run.sh index 5fb80736..59a598ba 100755 --- a/jigsaw-examples/example_splitpackage/m4/run.sh +++ b/jigsaw-examples/example_splitpackage/m4/run.sh @@ -22,11 +22,11 @@ mkdir -p run-result # Bar modules: Demonstrate runtime split package problem # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmainbar/pkgmainbar.Main 2>&1 + "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmainbar/pkgmainbar.Main 2>&1 # This should fail with LayerInstantiationException because both modules have package pkgbar # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting - if "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --add-modules modsplitbar2 --module modmainbar/pkgmainbar.Main 2>&1; then + if "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --add-modules modsplitbar2 --module modmainbar/pkgmainbar.Main 2>&1; then echo "A runtime exception was expected here" >&2 exit 1 fi diff --git a/jigsaw-examples/example_splitpackage_automatic-modules/README.adoc b/jigsaw-examples/example_splitpackage_automatic-modules/README.adoc index 61fe1a86..57429f10 100644 --- a/jigsaw-examples/example_splitpackage_automatic-modules/README.adoc +++ b/jigsaw-examples/example_splitpackage_automatic-modules/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_splitpackage_automatic-modules/m4/clean.sh b/jigsaw-examples/example_splitpackage_automatic-modules/m4/clean.sh index e61aa703..388e1ae1 100755 --- a/jigsaw-examples/example_splitpackage_automatic-modules/m4/clean.sh +++ b/jigsaw-examples/example_splitpackage_automatic-modules/m4/clean.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf amlib1 rm -rf amlib2 rm -rf classes1 diff --git a/jigsaw-examples/example_splitpackage_automatic-modules/m4/compile.sh b/jigsaw-examples/example_splitpackage_automatic-modules/m4/compile.sh index 70fa354f..9d417352 100755 --- a/jigsaw-examples/example_splitpackage_automatic-modules/m4/compile.sh +++ b/jigsaw-examples/example_splitpackage_automatic-modules/m4/compile.sh @@ -30,7 +30,6 @@ mkdir -p amlib1 mkdir -p amlib2 mkdir -p classes1 mkdir -p classes2 -mkdir -p mlib echo "=== Hybrid Compilation for Maven 4 ===" echo @@ -69,23 +68,11 @@ echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" echo "(Compiler args: --module-path amlib1)" -mvn clean compile +mvn clean package -# Create JARs directly to mlib (similar to original compile.sh) -echo -echo "Step 3: Package module as JAR in mlib/" -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar ${JAR_OPTIONS} --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" ${JAR_OPTIONS} --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 echo echo "✅ Hybrid compilation complete" diff --git a/jigsaw-examples/example_splitpackage_automatic-modules/m4/pom.xml b/jigsaw-examples/example_splitpackage_automatic-modules/m4/pom.xml index 56c6aadb..a98c7ad8 100644 --- a/jigsaw-examples/example_splitpackage_automatic-modules/m4/pom.xml +++ b/jigsaw-examples/example_splitpackage_automatic-modules/m4/pom.xml @@ -19,7 +19,6 @@ modmain - src/modmain/main/java @@ -35,6 +34,30 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_splitpackage_automatic-modules/m4/run.sh b/jigsaw-examples/example_splitpackage_automatic-modules/m4/run.sh index f418c765..4719ac32 100755 --- a/jigsaw-examples/example_splitpackage_automatic-modules/m4/run.sh +++ b/jigsaw-examples/example_splitpackage_automatic-modules/m4/run.sh @@ -31,6 +31,6 @@ echo # we do not see an error, all is fine # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \ - --module-path mlib"${PATH_SEPARATOR}"amlib1 \ + --module-path target"${PATH_SEPARATOR}"amlib1 \ --module modmain/pkgmain.Main . \ 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_spring-hibernate/README.adoc b/jigsaw-examples/example_spring-hibernate/README.adoc index fd5fe976..aa9b6361 100644 --- a/jigsaw-examples/example_spring-hibernate/README.adoc +++ b/jigsaw-examples/example_spring-hibernate/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== @@ -71,7 +71,7 @@ So we had to exclude the `asm` version from `plexus-java` (which wants `asm-6.0- The application now compiles, tests and runs with Java 9. -==== Step C: Introducing a JPMS / Jigsaw module +==== Step C: Introducing a Java Module [start=8] . We converted `mod.app`into a module by adding a `module-info`. diff --git a/jigsaw-examples/example_test/README.adoc b/jigsaw-examples/example_test/README.adoc index 1335b3fc..b9d06072 100644 --- a/jigsaw-examples/example_test/README.adoc +++ b/jigsaw-examples/example_test/README.adoc @@ -8,7 +8,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_test/m4/pom.xml b/jigsaw-examples/example_test/m4/pom.xml index 81bd55d7..f76bdb9e 100644 --- a/jigsaw-examples/example_test/m4/pom.xml +++ b/jigsaw-examples/example_test/m4/pom.xml @@ -36,12 +36,10 @@ modfib - src/modfib/main/java modfib - src/modfib/test/java test diff --git a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/README.adoc b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/README.adoc index 1825074c..147561a0 100644 --- a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/README.adoc +++ b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/clean.sh b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/clean.sh index 267a2a8e..4a3cfa2f 100755 --- a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/clean.sh +++ b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/clean.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf classes rm -rf cplib rm -rf run-result diff --git a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/compile.sh b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/compile.sh index e51fbf63..8ea4aeb8 100755 --- a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/compile.sh +++ b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/compile.sh @@ -28,7 +28,6 @@ export PATH="${M4_HOME}/bin:${PATH}" mkdir -p cplib mkdir -p classes/cpmain -mkdir -p mlib echo "=== Hybrid Compilation for Maven 4 ===" echo @@ -37,22 +36,10 @@ echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile +mvn clean package -# Create JARs for modules -echo -echo "Step 2: Package modules as JARs in mlib/" -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar ${JAR_OPTIONS} --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" ${JAR_OPTIONS} --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 echo echo "Step 3: Manually compile classpath code (cpmain)" diff --git a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/pom.xml b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/pom.xml index f9ca035f..d82d78cd 100644 --- a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/pom.xml +++ b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/pom.xml @@ -19,11 +19,9 @@ modb - src/modb/main/java modc - src/modc/main/java @@ -33,6 +31,41 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modc + package + + jar + + + ${project.build.outputDirectory}/modc + modc + + + + diff --git a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/run.sh b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/run.sh index 510d6d11..ded6852c 100755 --- a/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/run.sh +++ b/jigsaw-examples/example_unnamed-module-reflection-illegal-access/m4/run.sh @@ -38,35 +38,35 @@ echo "Checking variants of reflective access to java.base/jdk.internal.math.Doub echo echo "1 - reflective call without any options" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 1 - Expected exception but command succeeded" exit 1 fi echo echo "2 - reflective call with --illegal-access=permit" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --illegal-access=permit --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --illegal-access=permit --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 2 - Expected exception but command succeeded" exit 1 fi echo echo "3 - reflective call with --illegal-access=warn" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --illegal-access=warn --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --illegal-access=warn --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 3 - Expected exception but command succeeded" exit 1 fi echo echo "4 - reflective call with --illegal-access=deny" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --illegal-access=deny --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --illegal-access=deny --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 4 - Expected exception but command succeeded" exit 1 fi echo echo "5 - reflective call with explicit --add-opens" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --add-opens=java.base/jdk.internal.math=ALL-UNNAMED --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --add-opens=java.base/jdk.internal.math=ALL-UNNAMED --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseJDKInternal 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 5 - Expected success but got exception" exit 1 fi @@ -86,28 +86,28 @@ echo "Checking variants of reflective access to java.base/sun.net.PortConfig. It echo echo "6 - reflective call without any options" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 6 - Expected success but got exception" exit 1 fi echo echo "7 - reflective call with --illegal-access=permit" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --illegal-access=permit --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --illegal-access=permit --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 7 - Expected success but got exception" exit 1 fi echo echo "8 - reflective call with --illegal-access=warn" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --illegal-access=warn --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --illegal-access=warn --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 8 - Expected success but got exception" exit 1 fi echo echo "9 - reflective call with --illegal-access=deny" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --illegal-access=deny --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --illegal-access=deny --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 9 - Expected exception but command succeeded" exit 1 fi @@ -115,7 +115,7 @@ fi echo echo "10 - reflective call with explicit --add-opens" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --add-opens=java.base/sun.net=ALL-UNNAMED --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --add-opens=java.base/sun.net=ALL-UNNAMED --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaBaseSunNet 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 10 - Expected success but got exception" exit 1 fi @@ -135,35 +135,35 @@ echo "Checking variants of reflective access to java.desktop/com.sun.java.swing. echo echo "11 - reflective call without any options" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 11 - Expected success but got exception" exit 1 fi echo echo "12 - reflective call with --illegal-access=permit" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --illegal-access=permit --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --illegal-access=permit --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 12 - Expected success but got exception" exit 1 fi echo echo "13 - reflective call with --illegal-access=warn" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --illegal-access=warn --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --illegal-access=warn --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 13 - Expected success but got exception" exit 1 fi echo echo "14 - reflective call with --illegal-access=deny" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --illegal-access=deny --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --illegal-access=deny --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 14 - Expected exception but command succeeded" exit 1 fi echo echo "15 - reflective call with explicit --add-opens" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --add-opens=java.desktop/com.sun.java.swing.plaf.nimbus=ALL-UNNAMED --module-path mlib -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --add-opens=java.desktop/com.sun.java.swing.plaf.nimbus=ALL-UNNAMED --module-path target -cp cplib/cpmain.jar pkgcpmain.MainCallingJavaDesktop 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 15 - Expected success but got exception" exit 1 fi @@ -186,35 +186,35 @@ echo " class pkgbexportedqualified.BFromModuleButExportedQualified is exporte echo echo "16 - reflective call without any options" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --module-path mlib -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --module-path target -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 16 - Expected exception but command succeeded" exit 1 fi echo echo "17 - reflective call with --illegal-access=permit" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --illegal-access=permit --module-path mlib -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --illegal-access=permit --module-path target -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 17 - Expected exception but command succeeded" exit 1 fi echo echo "18 - reflective call with --illegal-access=warn" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --illegal-access=warn --module-path mlib -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --illegal-access=warn --module-path target -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 18 - Expected exception but command succeeded" exit 1 fi echo echo "19 - reflective call with --illegal-access=deny" echo "Should throw InaccessibleObjectException" -if "${JAVA_HOME}/bin/java" --illegal-access=deny --module-path mlib -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if "${JAVA_HOME}/bin/java" --illegal-access=deny --module-path target -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 19 - Expected exception but command succeeded" exit 1 fi echo echo "20 - reflective call with explicit --add-opens" echo "Should work without problems" -if ! "${JAVA_HOME}/bin/java" --add-opens=modb/pkgbinternal=ALL-UNNAMED --add-opens modb/pkgbexportedqualified=ALL-UNNAMED --module-path mlib -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then +if ! "${JAVA_HOME}/bin/java" --add-opens=modb/pkgbinternal=ALL-UNNAMED --add-opens modb/pkgbexportedqualified=ALL-UNNAMED --module-path target -cp cplib/cpmain.jar --add-modules modb pkgcpmain.MainCallingModB 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho; then echo "ERROR: Variant 20 - Expected success but got exception" exit 1 fi diff --git a/jigsaw-examples/example_unnamed-module_access-from-automatic-module/README.adoc b/jigsaw-examples/example_unnamed-module_access-from-automatic-module/README.adoc index ee6782d0..1f220108 100644 --- a/jigsaw-examples/example_unnamed-module_access-from-automatic-module/README.adoc +++ b/jigsaw-examples/example_unnamed-module_access-from-automatic-module/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/README.adoc b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/README.adoc index cdbbd15c..ab730327 100644 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/README.adoc +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/clean.sh b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/clean.sh index 267a2a8e..4a3cfa2f 100755 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/clean.sh +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/clean.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf classes rm -rf cplib rm -rf run-result diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/compile.sh b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/compile.sh index d180b42c..0253fa35 100755 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/compile.sh +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/compile.sh @@ -28,7 +28,6 @@ export PATH="${M4_HOME}/bin:${PATH}" mkdir -p cplib mkdir -p classes/cpb -mkdir -p mlib echo "=== Hybrid Compilation for Maven 4 ===" echo @@ -52,23 +51,11 @@ echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" echo "(Compiler args: --add-reads modmain=ALL-UNNAMED --class-path cplib/cpb.jar)" -mvn clean compile +mvn clean package -# Create JARs directly to mlib (similar to original compile.sh) -echo -echo "Step 3: Package modules as JARs in mlib/" -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar ${JAR_OPTIONS} --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" ${JAR_OPTIONS} --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 echo echo "✅ Hybrid compilation complete" diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/pom.xml b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/pom.xml index 4d56e297..f3cfea58 100644 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/pom.xml +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/pom.xml @@ -19,11 +19,9 @@ modb - src/modb/main/java modmain - src/modmain/main/java @@ -41,6 +39,41 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/run.sh b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/run.sh index c46b0059..c7598989 100755 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/run.sh +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module-reflection/m4/run.sh @@ -15,7 +15,7 @@ mkdir -p run-result # Run the Java code with modules on module-path and classpath code on classpath # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \ - --module-path mlib \ + --module-path target \ --class-path cplib/cpb.jar \ --module modmain/pkgmain.Main \ 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/README.adoc b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/README.adoc index 9db09e5d..b05a06aa 100644 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/README.adoc +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/clean.sh b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/clean.sh index 267a2a8e..4a3cfa2f 100755 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/clean.sh +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/clean.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf classes rm -rf cplib rm -rf run-result diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/compile.sh b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/compile.sh index 00336bef..dc432336 100755 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/compile.sh +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/compile.sh @@ -20,7 +20,6 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib mkdir -p cplib mkdir -p classes @@ -56,18 +55,8 @@ echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" echo "(Modules can access cpb on classpath via --add-reads modmain=ALL-UNNAMED)" -mvn clean compile +mvn clean package -# Create JARs for modules -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/pom.xml b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/pom.xml index abc04fe0..0b77fc67 100644 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/pom.xml +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/pom.xml @@ -18,11 +18,9 @@ modb - src/modb/main/java modmain - src/modmain/main/java @@ -40,6 +38,41 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/run.sh b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/run.sh index a81eac60..e7a8c3b0 100755 --- a/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/run.sh +++ b/jigsaw-examples/example_unnamed-module_access-from-explicit-module/m4/run.sh @@ -15,7 +15,7 @@ mkdir -p run-result # Run the Java code with cpb on classpath, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \ - --module-path mlib \ + --module-path target \ --class-path cplib/cpb.jar \ --module modmain/pkgmain.Main \ 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_unnamed-module_accessing-module-path/README.adoc b/jigsaw-examples/example_unnamed-module_accessing-module-path/README.adoc index 91223212..7adb88f5 100644 --- a/jigsaw-examples/example_unnamed-module_accessing-module-path/README.adoc +++ b/jigsaw-examples/example_unnamed-module_accessing-module-path/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/clean.sh b/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/clean.sh index 267a2a8e..4a3cfa2f 100755 --- a/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/clean.sh +++ b/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/clean.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf classes rm -rf cplib rm -rf run-result diff --git a/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/compile.sh b/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/compile.sh index b8d19d17..44525812 100755 --- a/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/compile.sh +++ b/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/compile.sh @@ -20,7 +20,6 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib mkdir -p cplib mkdir -p classes/cpb @@ -33,20 +32,9 @@ echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JAR for modb -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package # Step 2: Compile classpath code (cpb, cpmain) manually # Maven's Module Source Hierarchy cannot handle this, so we compile it manually @@ -64,9 +52,9 @@ fi pushd ../src > /dev/null 2>&1 for dir in cpb cpmain; do - echo "javac ${JAVAC_OPTIONS} -cp ../m4/mlib/*${PATH_SEPARATOR}../m4/classes/cpb -d ../m4/classes/${dir} --release 11 \$(find ${dir} -name \"*.java\")" + echo "javac ${JAVAC_OPTIONS} -cp ../m4/target/*${PATH_SEPARATOR}../m4/classes/cpb -d ../m4/classes/${dir} --release 11 \$(find ${dir} -name \"*.java\")" # shellcheck disable=SC2046,SC2086 # JAVAC_OPTIONS is intentionally unquoted for word splitting, the find command is intended to be expanded - "${COMPILE_JAVA_HOME}/bin/javac" ${JAVAC_OPTIONS} -cp ../m4/mlib/*"${PATH_SEPARATOR}"../m4/classes/cpb -d ../m4/classes/${dir} --release 11 $(find ${dir} -name "*.java") 2>&1 + "${COMPILE_JAVA_HOME}/bin/javac" ${JAVAC_OPTIONS} -cp ../m4/target/*"${PATH_SEPARATOR}"../m4/classes/cpb -d ../m4/classes/${dir} --release 11 $(find ${dir} -name "*.java") 2>&1 echo "jar $JAR_OPTIONS --create --file=../m4/cplib/${dir}.jar -C ../m4/classes/${dir} ." # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting diff --git a/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/pom.xml b/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/pom.xml index aae0b615..a2424b7b 100644 --- a/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/pom.xml +++ b/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/pom.xml @@ -19,7 +19,6 @@ modb - src/modb/main/java @@ -29,6 +28,30 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modb + package + + jar + + + ${project.build.outputDirectory}/modb + modb + + + + diff --git a/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/run.sh b/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/run.sh index c7dba101..1d90ea82 100755 --- a/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/run.sh +++ b/jigsaw-examples/example_unnamed-module_accessing-module-path/m4/run.sh @@ -16,7 +16,7 @@ mkdir -p run-result # --add-modules modb makes the module available even though not required # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting "${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \ - --module-path mlib \ + --module-path target \ --class-path cplib/cpmain.jar"${PATH_SEPARATOR}"cplib/cpb.jar \ --add-modules modb pkgcpmain.Main \ 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_uses-provides/README.adoc b/jigsaw-examples/example_uses-provides/README.adoc index 5231624f..d6b7fcd5 100644 --- a/jigsaw-examples/example_uses-provides/README.adoc +++ b/jigsaw-examples/example_uses-provides/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_uses-provides/m4/.gitignore b/jigsaw-examples/example_uses-provides/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_uses-provides/m4/.gitignore +++ b/jigsaw-examples/example_uses-provides/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_uses-provides/m4/clean.sh b/jigsaw-examples/example_uses-provides/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_uses-provides/m4/clean.sh +++ b/jigsaw-examples/example_uses-provides/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_uses-provides/m4/compile.sh b/jigsaw-examples/example_uses-provides/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_uses-provides/m4/compile.sh +++ b/jigsaw-examples/example_uses-provides/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_uses-provides/m4/pom.xml b/jigsaw-examples/example_uses-provides/m4/pom.xml index bfb9e5d4..9a9151d4 100644 --- a/jigsaw-examples/example_uses-provides/m4/pom.xml +++ b/jigsaw-examples/example_uses-provides/m4/pom.xml @@ -18,19 +18,15 @@ modmain - src/modmain/main/java modservice.impl.com - src/modservice.impl.com/main/java modservice.impl.net - src/modservice.impl.net/main/java modservicedefinition - src/modservicedefinition/main/java @@ -40,6 +36,63 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + modservice.impl.com + package + + jar + + + ${project.build.outputDirectory}/modservice.impl.com + modservice.impl.com + + + + modservice.impl.net + package + + jar + + + ${project.build.outputDirectory}/modservice.impl.net + modservice.impl.net + + + + modservicedefinition + package + + jar + + + ${project.build.outputDirectory}/modservicedefinition + modservicedefinition + + + + diff --git a/jigsaw-examples/example_uses-provides/m4/run.sh b/jigsaw-examples/example_uses-provides/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_uses-provides/m4/run.sh +++ b/jigsaw-examples/example_uses-provides/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_uses-provides_uses-in-client/README.adoc b/jigsaw-examples/example_uses-provides_uses-in-client/README.adoc index 68c8226b..489fef62 100644 --- a/jigsaw-examples/example_uses-provides_uses-in-client/README.adoc +++ b/jigsaw-examples/example_uses-provides_uses-in-client/README.adoc @@ -15,7 +15,7 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== diff --git a/jigsaw-examples/example_uses-provides_uses-in-client/m4/.gitignore b/jigsaw-examples/example_uses-provides_uses-in-client/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_uses-provides_uses-in-client/m4/.gitignore +++ b/jigsaw-examples/example_uses-provides_uses-in-client/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_uses-provides_uses-in-client/m4/clean.sh b/jigsaw-examples/example_uses-provides_uses-in-client/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_uses-provides_uses-in-client/m4/clean.sh +++ b/jigsaw-examples/example_uses-provides_uses-in-client/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_uses-provides_uses-in-client/m4/compile.sh b/jigsaw-examples/example_uses-provides_uses-in-client/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_uses-provides_uses-in-client/m4/compile.sh +++ b/jigsaw-examples/example_uses-provides_uses-in-client/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_uses-provides_uses-in-client/m4/pom.xml b/jigsaw-examples/example_uses-provides_uses-in-client/m4/pom.xml index d14d9182..bad3ec84 100644 --- a/jigsaw-examples/example_uses-provides_uses-in-client/m4/pom.xml +++ b/jigsaw-examples/example_uses-provides_uses-in-client/m4/pom.xml @@ -18,19 +18,15 @@ modmain - src/modmain/main/java modservice.impl.com - src/modservice.impl.com/main/java modservice.impl.net - src/modservice.impl.net/main/java modservicedefinition - src/modservicedefinition/main/java @@ -40,6 +36,63 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + modservice.impl.com + package + + jar + + + ${project.build.outputDirectory}/modservice.impl.com + modservice.impl.com + + + + modservice.impl.net + package + + jar + + + ${project.build.outputDirectory}/modservice.impl.net + modservice.impl.net + + + + modservicedefinition + package + + jar + + + ${project.build.outputDirectory}/modservicedefinition + modservicedefinition + + + + diff --git a/jigsaw-examples/example_uses-provides_uses-in-client/m4/run.sh b/jigsaw-examples/example_uses-provides_uses-in-client/m4/run.sh index f17cda9b..fa508d91 100755 --- a/jigsaw-examples/example_uses-provides_uses-in-client/m4/run.sh +++ b/jigsaw-examples/example_uses-provides_uses-in-client/m4/run.sh @@ -14,4 +14,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/jigsaw-examples/example_version/README.adoc b/jigsaw-examples/example_version/README.adoc index 5c0c4a62..5a523384 100644 --- a/jigsaw-examples/example_version/README.adoc +++ b/jigsaw-examples/example_version/README.adoc @@ -15,13 +15,14 @@ Part of the full xref:../../README.adoc[Java 9 Jigsaw modules example] suite. ==== Originally written by https://github.com/mrtnlhmnn[Martin Lehmann], https://github.com/kristines[Kristine Schaal] and https://github.com/rgrammes[Rüdiger Grammes] (cf. https://github.com/accso/java9-jigsaw-examples[original repository]). -Migrated for JPMS support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. +Migrated for Java Modules support documentation of Apache Maven^TM^ in the course of the https://open-elements.com/support-care-maven/[Maven Support & Care] program by https://github.com/ascheman[Gerd Aschemann] (and other team members) as https://github.com/support-and-care/java9-jigsaw-examples[forked repository]. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. ==== == What is this example about? -This example is not really about the Jigsaw/JPMS module system. Instead it shows that usage of the new versioning scheme. +This example is not really about Java Modules. +Instead, it shows that usage of the new versioning scheme. For more background information, refer to https://openjdk.java.net/jeps/223[JEP 223]. diff --git a/jigsaw-examples/example_version/m4/.gitignore b/jigsaw-examples/example_version/m4/.gitignore index 25275013..52aee332 100644 --- a/jigsaw-examples/example_version/m4/.gitignore +++ b/jigsaw-examples/example_version/m4/.gitignore @@ -1,3 +1,2 @@ target/ -mlib/ run-result/ diff --git a/jigsaw-examples/example_version/m4/clean.sh b/jigsaw-examples/example_version/m4/clean.sh index 94f380eb..d7faaade 100755 --- a/jigsaw-examples/example_version/m4/clean.sh +++ b/jigsaw-examples/example_version/m4/clean.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash rm -rf target -rm -rf mlib rm -rf run-result diff --git a/jigsaw-examples/example_version/m4/compile.sh b/jigsaw-examples/example_version/m4/compile.sh index f872668c..3d6b7cb8 100755 --- a/jigsaw-examples/example_version/m4/compile.sh +++ b/jigsaw-examples/example_version/m4/compile.sh @@ -20,23 +20,12 @@ fi # Add Maven 4 to PATH export PATH="${M4_HOME}/bin:${PATH}" -mkdir -p mlib echo "mvn --version" mvn --version echo -echo "mvn clean compile" +echo "mvn clean package" echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)" -mvn clean compile - -# Create JARs directly to mlib (similar to original compile.sh) -pushd target/classes > /dev/null 2>&1 -for dir in */; -do - MODDIR=${dir%*/} - echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ." - # shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting - "${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1 -done -popd >/dev/null 2>&1 +mvn clean package + diff --git a/jigsaw-examples/example_version/m4/pom.xml b/jigsaw-examples/example_version/m4/pom.xml index a326c096..c50331dd 100644 --- a/jigsaw-examples/example_version/m4/pom.xml +++ b/jigsaw-examples/example_version/m4/pom.xml @@ -18,7 +18,6 @@ modmain - src/modmain/main/java @@ -28,6 +27,30 @@ maven-compiler-plugin 4.0.0-beta-3 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.2 + + + + default-jar + none + + + + modmain + package + + jar + + + ${project.build.outputDirectory}/modmain + modmain + + + + diff --git a/jigsaw-examples/example_version/m4/run.sh b/jigsaw-examples/example_version/m4/run.sh index ca62daff..f7f36bc5 100755 --- a/jigsaw-examples/example_version/m4/run.sh +++ b/jigsaw-examples/example_version/m4/run.sh @@ -17,4 +17,4 @@ mkdir -p run-result # Run the Java code, save output to run-result/run.txt, and display with highlighting # shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting -"${RUNTIME_JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho +"${RUNTIME_JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path target --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho diff --git a/pom.xml b/pom.xml index c87e33f5..6ff8d6fd 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,11 @@ 11 11 3.2.0 + + + support-and-care + java9-jigsaw-examples + main @@ -49,6 +54,7 @@ true false . + https://github.com/${github.repo.owner}/${github.repo.name}/tree/${github.branch}/jigsaw-examples