Skip to content

Commit 52b06ad

Browse files
committed
Restructure example_resources m4 src layout
Reorganize m4/src directory to follow proper Maven directory structure with separate java/ and resources/ subdirectories for each module. This change addresses Java compiler limitations with symlinked source files. Changes: - Restructure m4/src with Maven-standard layout: - src/{module}/main/java/ for Java source files - src/{module}/main/resources/ for resource files - Copy all source files (symlinks don't work with javac) - Update pom.xml to read resources from new structure - Add verify-sources.sh to ensure consistency with ../src - Update verify.sh to call verify-sources.sh as Step 0 - Document structure and symlink limitation in README.adoc Technical limitation: The Java compiler cannot resolve module structure when source files are symlinked from outside the module source path (--module-source-path). When javac encounters such symlinks, it fails with "module not found on module source path" errors. Therefore, m4/src/ contains full copies of all files from ../src/, reorganized into Maven's standard directory layout. The verify-sources.sh script validates that all files remain identical between ../src and m4/src despite different layouts, running automatically as part of the verification workflow. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Introduced in the course of support-and-care/maven-support-and-care#137
1 parent 37182a3 commit 52b06ad

File tree

34 files changed

+412
-215
lines changed

34 files changed

+412
-215
lines changed

jigsaw-examples/example_resources/README.adoc

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,52 @@ include::m4/run-result/run.txt[]
6767
[[sec:maven-4-migration]]
6868
== Maven 4 Migration
6969

70-
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].
70+
This example was migrated to Maven 4 with a special source tree structure to properly separate Java source files from resources, following Maven conventions.
7171

72-
The source files follow the standard Module Source Hierarchy setup.
73-
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.
72+
The `m4/src` directory follows proper Maven directory conventions with separate `java/` and `resources/` subdirectories:
73+
74+
[source]
75+
----
76+
m4/src/
77+
├── modb/main/
78+
│ ├── java/ # Java source files only
79+
│ │ ├── module-info.java
80+
│ │ ├── pkgb/B.java
81+
│ │ └── pkgbinternal/BInternal.java
82+
│ └── resources/ # Resource files only
83+
│ ├── pkgb/b.properties
84+
│ ├── pkgbinternal/binternal.properties
85+
│ └── resources.modb/resources.properties
86+
├── modc/main/
87+
│ ├── java/ # Java source files only
88+
│ │ ├── module-info.java
89+
│ │ ├── pkgc/C.java
90+
│ │ └── pkgcinternal/CInternal.java
91+
│ └── resources/ # Resource files only
92+
│ ├── cnopackage.properties
93+
│ ├── pkgc/c.properties
94+
│ ├── pkgcinternal/cinternal.properties
95+
│ └── resources.modc/resources.properties
96+
└── modmain/main/
97+
└── java/ # Java source files only (no resources)
98+
├── module-info.java
99+
├── pkgmain/Main.java
100+
└── pkgmaininternal/IdGen.java
101+
----
102+
103+
This structure differs from the original `src/` directory where Java and resource files coexist in the same package directories.
104+
The Maven build properly handles resources through explicit `maven-resources-plugin` configuration that copies resource files from `src/<module>/main/resources` to `target/classes/<module>`.
105+
106+
[CAUTION]
107+
.Why Source Files Are Copied, Not Symlinked
108+
====
109+
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/`.
110+
111+
The Java compiler cannot properly resolve module structure when individual source files are symlinked from locations outside the module source path.
112+
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.
113+
114+
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.
115+
116+
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.
117+
This script runs automatically as part of `m4/verify.sh`.
118+
====

jigsaw-examples/example_resources/m4/pom.xml

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@
5252
<outputDirectory>${project.build.directory}/classes/modb</outputDirectory>
5353
<resources>
5454
<resource>
55-
<directory>src/modb/main/java</directory>
56-
<includes>
57-
<include>**/*.properties</include>
58-
<include>**/*.txt</include>
59-
</includes>
60-
<excludes>
61-
<exclude>**/*.java</exclude>
62-
</excludes>
55+
<directory>src/modb/main/resources</directory>
6356
</resource>
6457
</resources>
6558
</configuration>
@@ -74,36 +67,7 @@
7467
<outputDirectory>${project.build.directory}/classes/modc</outputDirectory>
7568
<resources>
7669
<resource>
77-
<directory>src/modc/main/java</directory>
78-
<includes>
79-
<include>**/*.properties</include>
80-
<include>**/*.txt</include>
81-
</includes>
82-
<excludes>
83-
<exclude>**/*.java</exclude>
84-
</excludes>
85-
</resource>
86-
</resources>
87-
</configuration>
88-
</execution>
89-
<execution>
90-
<id>copy-modmain-resources</id>
91-
<phase>process-resources</phase>
92-
<goals>
93-
<goal>copy-resources</goal>
94-
</goals>
95-
<configuration>
96-
<outputDirectory>${project.build.directory}/classes/modmain</outputDirectory>
97-
<resources>
98-
<resource>
99-
<directory>src/modmain/main/java</directory>
100-
<includes>
101-
<include>**/*.properties</include>
102-
<include>**/*.txt</include>
103-
</includes>
104-
<excludes>
105-
<exclude>**/*.java</exclude>
106-
</excludes>
70+
<directory>src/modc/main/resources</directory>
10771
</resource>
10872
</resources>
10973
</configuration>

jigsaw-examples/example_resources/m4/src/modb/main/java

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module modb {
2+
requires transitive modc;
3+
4+
exports pkgb;
5+
opens pkgb;
6+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package pkgb;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.Properties;
6+
7+
import pkgc.*;
8+
9+
public class B {
10+
public String doIt() {
11+
return "from B";
12+
}
13+
14+
public C getMyC() {
15+
return new C();
16+
}
17+
18+
// access resources in modb
19+
public String getTextFromProperties() throws IOException {
20+
String resourceFileName = "/resources.modb/resources.properties"; // now we get modb's resources.properties
21+
22+
final Properties properties = new Properties();
23+
try (final InputStream stream = B.class.getModule().getResourceAsStream(resourceFileName)) {
24+
properties.load(stream);
25+
}
26+
return properties.getProperty("text", "modb's resources properties not found in modb");
27+
}
28+
29+
// access resources in modc (from modb)
30+
public String getTextFromMODCsProperties() throws IOException {
31+
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)
32+
// Note that just an export on this package name is not sufficient for access!
33+
34+
final Properties properties = new Properties();
35+
try (final InputStream stream = C.class.getModule().getResourceAsStream(resourceFileName)) {
36+
properties.load(stream);
37+
}
38+
String propertyFromMODC = properties.getProperty("text");
39+
if (propertyFromMODC == null) {
40+
return "modc's resources properties not found via modb";
41+
}
42+
else {
43+
return propertyFromMODC + " - but retrieved via modb!";
44+
}
45+
}
46+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package pkgbinternal;
2+
3+
public class BInternal {
4+
// does not do anything - just there to ensure that there is an package pkgbinternal
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Can only be accessed from outside modb, if package pkgb is open'ed in modb's module-info
2+
text=Hello World, from modb's b.properties (whose package is opened)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Can only be accessed from outside modb, if package pkgbinternal would be open'ed in modb's module-info
2+
text=Hello World, from modb's binternal.properties (whose package is not opened)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Can only be accessed from outside modb, if package resources.modb would be open'ed in modb's module-info
2+
text=Hello World, from modb's resources.properties

jigsaw-examples/example_resources/m4/src/modc/main/java

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)