I'm using maven to build the project and compile failed because I put class Test2 in Test.java,
but is it because of maven or simply because java itself doesn't support this?
BTW,how can I open a maven project with eclipse?
解决方案
A public class called ClassName must (in most cases) be defined in a file called ClassName.java.
Edit
Although this is not a requirement of the Java language, most (if not all) implementations of Java, the above mentioned relationship between the class name and file name must hold, or a compiler error will result.
(For more information, please refer to Jon Skeet's answer.)
In the section, it describes how the directory structure can be mapped to a fully-qualified class name in Java, which leads to a requirement that the .class file which contains the bytecode for a class must reside in a path that resembles that of the fully-qualified class name.
The original answer which incorrectly stated that the naming scheme is a requirement has been edited.