Maven项目未在Eclipse中被视为Java [英] Maven project not being treated as Java in Eclipse

查看:73
本文介绍了Maven项目未在Eclipse中被视为Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个有很多不同的Maven项目的项目中.我在这些项目上进行了大量的JUnit测试,通常情况下效果很好.我打开Eclipse,右键单击包资源管理器->导入...现有的Maven项目,然后就可以导入项目了.我可以构建,向下钻取到src/test/java ...右键单击该文件,然后执行Run As JUnit测试.时不时地,我无法使它正常工作.如果我右键单击以执行运行,则得到的只是AspectJ/Java应用程序.没有JUnit测试.

I'm working on a project that has lots of different Maven projects. I've been doing a bunch of JUnit testing on these projects, and usually this goes well. I open up Eclipse, right click in package explorer->Import... Existing Maven Projects and I'm able to import the project fine. I can build, drill down to src/test/java... Right click on the file and do a Run As JUnit test. Every now and then though, I can't get this to work. If I right click to do a Run As, all I get is AspectJ/Java application. There's no JUnit tests.

我注意到项目文件夹旁边的图标只有一个M和一个文件夹图标,而对于能正常工作的项目,有一个文件夹M和一个AJ.我还注意到,似乎没有像普通Java项目那样将文件分类到它们的包中.似乎没有将项目视为AspectJ项目.如何让Eclipse将该Maven项目识别为Java项目?

I noticed that the icon next to the project folder only has an M and a folder icon, whereas with projects that do work, there's a folder, M, AND a AJ. I've also noticed that it doesn't seem to sort the files into their packages like normal Java projects. It seems like it's not treating the project as an AspectJ project. How do I get Eclipse to recognize this Maven project as a Java project?

推荐答案

应该有几个现有的答案,但是那些建议添加Java facet的答案只有在您的项目已经存在时才起作用(或者您想将其转换为)是一种多面性质,建议您更改pom.xml的性质只有在您随后将项目重新导入为Maven项目时才有效.

Several of the existing answers should work, but those suggesting to add a Java facet will only work if your project already is of (or you want to convert it to) a faceted nature, and the one suggesting you change your pom.xml will only work if you then re-import your project as a maven project.

如果您要修复"现有项目,即添加Java性质而不将其转换为多面形式且无需删除和重新导入,则只需编辑.project文件(外部或使用Navigator视图)在Eclipse中,因为它不会显示在您的软件包浏览器中),并将Java构建器和Java性质添加到现有的Maven构建器/性质中:

If you'd like to "fix" your existing project, i.e. add a Java nature without converting it to faceted form and without deleting and re-importing, just edit your .project file (externally, or with the Navigator view in eclipse, as it won't show up in your package explorer) and add the java builder and java nature to the existing 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).

Note the different capitalisation (javabuilder but maven2Builder, javanature but maven2Nature).

保存后,它将自动重新构建.您可能必须手动添加任何源文件夹(Project properties-> Java Build Path-> Source选项卡-> Add Folder....

As soon as you save, it should re-build automatically. You may have to manually add any source folders (Project properties -> Java Build Path -> Source tab -> Add Folder....

这篇关于Maven项目未在Eclipse中被视为Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆