I use maven to build the project, and failed to compile because I put the Test2 class in Test.java,
The source files must be specified after the public class that they contain, adding the suffix .java . In your case, the source file for the open Test2 class should be Test2.java 1 .
Is it because of maven or simply because Java itself does not support it?
The Java compiler, javac , complains, not Maven (Maven does not change the behavior of the compiler).
how can i open maven project using eclipse?
Use the Maven Eclipse Plugin (i.e. the plugin for Maven) and just run mvn eclipse:eclipse in your project and then Import ... as Existing projects into the workspace in Eclipse. You will need to set the classpath variable M2_REPO, indicating the use of the local repository. See Usage for more details.
Or (and that is exclusive or) install m2eclipse (that is, a plug-in for Eclipse that expands so that it can understand Maven projects and interact with it bi-directionally) and Import ... your project as Existing Maven projects .. p>
If EXCLUSIVE is not clear enough, it means: use one or the other, but not both at the same time.
1 As John Skeet mentioned, JLS allows this limitation for file implementations. This does not apply when using a database to store Java constructs (for example, Visual Age for Java). But in your case it is.
source share