转自:http://www.cnblogs.com/xiaona/p/4837b46b68d3f33642d0f470cad05101.html
建立好一个Maven项目后,如果Java Resources资源文件下没有src/main/java文件夹,并且在手动创建这个文件时提示“已存在文件”。
这说明,在这个项目配置中已经有了src/main/java这个文件夹,至于为什么不显示,我暂时也还不清楚,希望谁明白了跟我下,谢了。(已解决)
第一种方法: 打开项目的classpath文件:如下
<?xml version=
"1.0" encoding=
"UTF-8"?>
<classpath>
<classpathentry kind= "src" output= "target/test-classes" path= "src/test/java">
< attributes>
<attribute name= "optional" value= "true"/>
<attribute name= "maven.pomderived" value= "true"/>
</ attributes>
</classpathentry>
<classpathentry kind= "src" path= "src/main/java"/>
<classpathentry kind= "src" path= "src/main/resources"/>
<classpathentry kind= "src" output= "target/test-classes" path= "src/test/resources"/>
<classpathentry kind= "con" path= "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
< attributes>
<attribute name= "maven.pomderived" value= "true"/>
<attribute name= "org.eclipse.jst.component.dependency" value= "/WEB-INF/lib"/>
</ attributes>
</classpathentry>
<classpathentry kind= "con" path= "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
< attributes>
<attribute name= "owner.project.facets" value= "java"/>
</ attributes>
</classpathentry>
<classpathentry kind= "output" path= "target/classes"/>
</classpath>
<classpath>
<classpathentry kind= "src" output= "target/test-classes" path= "src/test/java">
< attributes>
<attribute name= "optional" value= "true"/>
<attribute name= "maven.pomderived" value= "true"/>
</ attributes>
</classpathentry>
<classpathentry kind= "src" path= "src/main/java"/>
<classpathentry kind= "src" path= "src/main/resources"/>
<classpathentry kind= "src" output= "target/test-classes" path= "src/test/resources"/>
<classpathentry kind= "con" path= "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
< attributes>
<attribute name= "maven.pomderived" value= "true"/>
<attribute name= "org.eclipse.jst.component.dependency" value= "/WEB-INF/lib"/>
</ attributes>
</classpathentry>
<classpathentry kind= "con" path= "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
< attributes>
<attribute name= "owner.project.facets" value= "java"/>
</ attributes>
</classpathentry>
<classpathentry kind= "output" path= "target/classes"/>
</classpath>
会出现path属性为:src/main/java的classpathentry节点,这时删除我们需要新建的的节点就可以,比如
<classpathentry kind=
"src"
path=
"src/main/java"
/>
。在Java Resources下重新建立src/main/java文件夹,就不会出现问题了。
第二种方法:这是最便利的一种。在项目上右键选择properties,然后点击java build path,在Librarys下,编辑JRE System Library,选择workspace default jre就可以了。
备注:上面是网友的解决办法 不过我没有去尝试 我采用的是新建src/main/其他名字 然后再重命名的方法