I have the following directory structure within my project:
src/
├── main
│ ├── java
│ │ └── com
│ │ └── soebes
│ │ └── packages
│ │ └── f1
│ │ └── First.java
│ └── resources
│ └── com
│ └── soebes
│ └── packages
│ └── f1
│ └── First
│ └── test.txt
└── test
├── java
│ └── com
│ └── soebes
│ └── packages
│ └── f1
│ └── FirstTest.java
└── resources
└── com
└── soebes
└── packages
└── f1
└── FirstTest
└── test.txt
As you can see I have a package name com/soebes/packages/f1/First
in my resources directory which has the same name as a class in my src/main/java/.../First.java
directory (except the .java
). The whole project compiles without any issue.
If you take a look into the resulting target
directory it looks fine:
target/
├── classes
│ └── com
│ └── soebes
│ └── packages
│ └── f1
│ ├── First
│ │ └── test.txt
│ └── First.class
....
└── test-classes
└── com
└── soebes
└── packages
└── f1
├── FirstTest
│ └── test.txt
└── FirstTest.class
Update: Also the resulting JAR looks fine and can built without any issue:
package (main)$ unzip -t target/packages-examples-1.0-SNAPSHOT.jar
Archive: target/packages-examples-1.0-SNAPSHOT.jar
testing: META-INF/MANIFEST.MF OK
testing: META-INF/ OK
testing: com/ OK
testing: com/soebes/ OK
testing: com/soebes/packages/ OK
testing: com/soebes/packages/f1/ OK
testing: com/soebes/packages/f1/First/ OK
testing: META-INF/maven/ OK
testing: META-INF/maven/com.soebes.jvm.packages/ OK
testing: META-INF/maven/com.soebes.jvm.packages/packages-examples/ OK
testing: com/soebes/packages/f1/First/test.txt OK
testing: com/soebes/packages/f1/First.class OK
testing: META-INF/maven/com.soebes.jvm.packages/packages-examples/pom.xml OK
testing: META-INF/maven/com.soebes.jvm.packages/packages-examples/pom.properties OK
testing: META-INF/INDEX.LIST OK
No errors detected in compressed data of target/packages-examples-1.0-SNAPSHOT.jar.
The question is simply: Is this allowed?
Compiling on plain command line works fine. Also using in in IDEA IntelliJ as well.
Eclipse seemed to be having issues with that. It produces an errors like The type FirstTest collides with a package
... it looks like that it analysis the target
directory.
I've already searched through the JLS but couldn't find anything related to that or may be I have overseen something like that.
From a technical point of view there shouldn't be an issue the class is FirstTest.class
which is a file and the directory are two different things.
So in consequence if this allowed the behaviour in Eclipse is a bug or if this is not allowed it would meant IDEA and Maven/Javac having an issue?
The given example can be found on Github for further investigation.
Environment:
Apache Maven:
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /Users/khmarbaise/tools/maven Java version: 11.0.8, vendor: AdoptOpenJDK, runtime: /Users/khmarbaise/.sdkman/candidates/java/11.0.8.hs-adpt Default locale: en_GB, platform encoding: UTF-8 OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
Eclipse:
Version: 2020-06 (4.16.0) Build id: 20200615-1200
IDEA IntelliJ
IntelliJ IDEA 2020.3.1 (Ultimate Edition) Build #IU-203.6682.168, built on December 29, 2020 Runtime version: 11.0.9.1+11-b1145.63 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 10.14.6
Update: 02/15/2021: https://bugs.eclipse.org/bugs/show_bug.cgi?id=571218