eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Support "." in package folder name
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
Some developers choose to use a single folder to represent several packages, e.g. a single folder `a.b.c` instead of three folders `a/b/c` to represent package `a.b.c`.
IMO It's not against the specs about packages in [JLS §7.6](https://docs.oracle.com/javase/specs/jls/se17/html/jls-7.html#jls-7.6), but in Eclipse it won't work. Any .java file under folder name containing "." seems to be recognized as under default package, with below error message.
```java
package x.y; // ERROR: The declared package "x.y" does not match the expected package ""
public class Foo {}
```
Folder structure:
```
.
|____src
| |____x.y
| | |____Foo.java
```
Besides eclipse project, I also tried a simple Maven project, but in Eclipse it's the same error as above.

Folder structure of source files:
```
.
|__src
| |__main
| | |__java
| | | |__com
| | | | |__ms
| | | | | |__x.y
| | | | | | |__Foo.java
| | | | | |__a
| | | | | | |__b
| | | | | | | |__Bar.java
```
Folder structure of generated classes:
```
|__target
| |__classes
| | |__com
| | | |__ms
| | | | |__x.y // WRONG: the classes should be generated into folder x/y
| | | | | |__Foo.class
| | | | |__a
| | | | | |__b
| | | | | | |__Bar.class
```
The same project can be successfully compiled by command `mvn clean compile`, producing .class files in correct location. Other IDE like IntelliJ IDEA also works well. Since it's not against JLS and is also supported by other tools, I think it would be great if JDT can support that, which unblocks developers to work with such projects.
Related issue:
https://github.com/redhat-developer/vscode-java/issues/1406
Topics:
https://stackoverflow.com/questions/61125828/compiler-error-when-the-folder-contains-dot
https://stackoverflow.com/questions/10719306/java-package-folders-with-a-dot-in-the-name
Contributor guide
Assessment
This issue has not been assessed yet.