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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
publicclass calledClassNamemust (in most cases) be defined in a file calledClassName.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.)
The reason for this can be found by reading Section 7.2: Packages of The Java Language Specification, Third Edition.
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
.classfile 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.