我注意到项目文件夹旁边的图标只有 M 和文件夹图标,而能正常工作的项目则有文件夹、M 和 AJ 的图标。我还注意到它似乎没有像普通 Java 项目那样将文件分类到它们的包中。它似乎没有把这个项目当作一个 AspectJ 项目来处理。我该如何让 Eclipse 将这个 Maven 项目识别为一个 Java 项目?
现有的几个答案应该都可以解决问题,但是建议添加Java facet的方法只适用于已经是faceted性质的项目(或者你想将其转换为faceted),建议更改pom.xml
的方法只在您将项目重新导入为Maven项目后才能生效。
如果您想“修复”现有项目,即添加Java性质而不将其转换为faceted形式,也不删除并重新导入,请编辑您的.project
文件(在Eclipse中使用Navigator视图外部打开,因为它不会显示在您的包资源管理器中)并将Java builder和Java nature添加到现有的Maven builder/nature中:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>yourprojectname</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<!-- add this build command -->
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<!-- this would've already been there -->
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<!-- add this nature -->
<nature>org.eclipse.jdt.core.javanature</nature>
<!-- this would've already been there -->
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
请注意不同的大小写(javabuilder 但 maven2Builder,javanature 但 maven2Nature)。
一旦您保存,它应该自动重新构建。您可能需要手动添加任何源文件夹(项目属性
-> Java 构建路径
-> 源
选项卡 -> 添加文件夹...
)。
右击 Project
-> Properties
-> Project Facets
,然后选择适用于您情况的所有面貌(例如Java)。
mvn eclipse:eclipse会创建必要的.project文件,这将为项目添加java性质和其他属性。
mvn eclipse:eclipse
命令之前,可能还需要执行 mvn eclipse:clean
。最后按下 alt+F5
,我的 Eclipse 工作区就恢复正常了。 - Ghurdyl我曾经遇到同样的问题,下面的步骤解决了我的问题:
1- 打开有问题的项目的 pom.xml 文件。
2- 在总览选项卡中检查 Artifact/Packaging 设置。
3- 如果设置为 "pom",请将其更改为 "jar"。
4- 保存更改,然后只从 eclipse 中删除项目,并重新导入它。
希望这可以帮助你!
这取决于Eclipse项目面向的属性(如果你正在使用Java EE),我建议你右键单击项目属性并查看为其定义了哪些属性。
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>yourprojectName</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
pom.xml
文件,查看未获得AspectJ性质(项目上的AJ)的项目。它们是否缺少AspectJ-Maven插件?它们应该有如下部分:<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<!-- use this goal to weave all your main classes -->
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<complianceLevel>1.6</complianceLevel>
</configuration>
</plugin>
同时也请看一下他的问题:Eclipse中的Maven/AJDT项目