eclipse中运行maven项目时出现问题,无法识别为Java项目

发布于 2024-11-11 02:47:36 字数 787 浏览 2 评论 0原文

我已将现有的 Maven 项目导入到 Eclipse 中。我尝试设置 JUnit 测试的配置,但我的项目不会作为可测试项目出现。当我手动输入项目名称时,我收到以下消息:

指定的项目不是java项目

我还注意到,当键入代码并尝试调用方法(例如“System.out”)时,当我键入句点时会弹出一条消息,显示:

该编译单元不在java项目的构建路径上

此外,当我右键单击该项目并导航到“构建路径”时,没有可用的操作。

在这里和其他地方查看了这一点后,我遵循了以下建议,但没有成功:

我已经验证了 .project 和 .classpath 文件的存在

我已经在 .project 文件中查看并验证了包含javanature

我运行了 mvn eclipse:eclipse

我在 PackageExplorer > 中右键单击了该项目;梅文>更新项目配置

Java 没有被列为项目方面,但我不确定是否应该弄乱它,因为我尝试单击它,这导致整个项目充满错误(我认为与构建路径有关,但是我不太记得了)。删除 Java 作为一个方面并没有消除错误,我不得不从头开始重新导入项目。

抱歉,如果其中有任何含糊之处,感谢您的帮助。

我正在使用 m2eclipse。

编辑:只需从我的工作区中删除项目,删除所有 .project、.classpath 文件和 .settings 文件夹,然后重新导入即可解决问题。我不知道为什么第一次没有成功。

I've imported an existing maven project into Eclipse. I tried to set up the configurations for a JUnit test, and my project wouldn't come up as a testable project. When I typed in the project name manually, I was given the message:

Specified project is not a java project

I've also noticed that when typing code and trying to call a method e.g. "System.out" a message pops up when I type the period, saying:

This compilation unit is not on the build path of a java project

Additionally, there are no actions available when I right click the project and navigate to Build Path.

Having looked this up on here and elsewhere, I've followed the following pieces of advice, without success:

I've verified the existence of .project and .classpath files

I've looked in the .project file and verified the inclusion of a javanature

I've run mvn eclipse:eclipse

I've right-clicked the project in the PackageExplorer > Maven > Update Project Configuration

Java is not listed as a project facet but I'm not sure I should mess with that because I've tried clicking that, and that caused the entire project to be filled with errors (I think related to build path, but I can't quite remember). Removing Java as a facet didn't get rid of the errors and I had to re-import the project from scratch.

Sorry if any of this is vague, and thanks for the help.

I'm using m2eclipse.

EDIT: Problem was solved simply by deleting the project from my workspace, deleting all .project, .classpath files and .settings folders, and re-importing. I don't know why it didn't work the first time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

叫嚣ゝ 2024-11-18 02:47:36

我已经运行了 mvn eclipse:eclipse
我右键单击了该项目
包资源管理器>梅文>更新
项目配置

这两者应该是互斥的。您可以使用 eclipse:eclipse 从外部管理项目,也可以使用 m2eclipse 从内部管理项目。不要混合它们。

问题的可能原因:

打包是POM(也许这是多模块项目的根,在这种情况下您必须导入模块项目)。 m2eclipse 不会将 Java 性质添加到 POM 项目中(eclipse:eclipse 也不会,顺便说一句)

I've run mvn eclipse:eclipse
I've right-clicked the project in the
PackageExplorer > Maven > Update
Project Configuration

Those two should be mutually exclusive. Either you manage a project from the outside using eclipse:eclipse or from the inside using m2eclipse. Don't mix them.

Possible cause of the problem:

The packaging is POM (perhaps this is the root of a multi-module project, in which case you have to import the module projects). m2eclipse doesn't add the Java nature to POM projects (nor does eclipse:eclipse, btw)

守望孤独 2024-11-18 02:47:36

确保 Eclipse 中是否有 M2 插件,并且系统中安装了 Maven 2.7 以上版本。

之后运行
mvn eclipse:clean 然后
mvn eclipse:eclipse

.classpath.project 将在您的项目文件夹中创建。
一切都应该好起来。

Make sure if you have M2 plugin in Eclipse, you have Maven 2.7 above installed in your system.

After that run
mvn eclipse:clean then
mvn eclipse:eclipse.

.classpath and .project will be created in your project folders.
Everything should be fine.

嘿哥们儿 2024-11-18 02:47:36

请关注以下网站..
右键单击项目,转到“属性”,然后选择“项目方面”。这会将其转换为 java/dynamic web 项目以供使用。

pls follow the below website..
Right click on the project, go to Properties, then select Project Facets. this will convert it to a java/dynamic web projects for the use.

鹿! 2024-11-18 02:47:36

我正在使用
版本:Indigo 服务版本 2
Build id: 20120216-1857

我还发现,在安装 Maven 插件后,“Project Explorer”-右键单击“我的项目”没有列出选项“Maven”或“configure”。

阅读上述内容后,我尝试在“Package Explorer”上执行相同的操作,令我惊讶的是它有效。现在“Project Explorer”也可以使用了!

I'm using
Version: Indigo Service Release 2
Build id: 20120216-1857

I also found that after I installed the Maven plugin that 'Project Explorer' - Right click on 'my project' did not list option "Maven" or "configure".

On reading the above, I tried doing the same on "Package Explorer" and to my surprise it worked. And now 'Project Explorer' works too!

看透却不说透 2024-11-18 02:47:36

我遇到了似乎同样的问题。就我而言,我正在检查一个包含多个(父/子)pom 的 Maven 项目。

如果您的存储库/分支中的最高级别 Maven 项目仅管理子 pom,则它可能根本不包含 Java 定义。您需要在 Eclipse 中将这些子项目作为独立项目打开。

您可以通过右键单击您的项目 -> 来完成此操作导入-> Maven->现有 Maven 项目 ->然后选择您要更改的子项目。

I had what seemed like the same issue. In my case, I was checking out a Maven project that contained multiple (parent/child) poms.

If the highest level Maven project within your repository/branch simply manages child poms, it may not contain Java definitions at all. You will need to open these child projects as an independent project within Eclipse.

You can do this by right clicking on your project -> Import -> Maven -> Existing Maven Projects -> then select child project you are wanting to change.

自找没趣 2024-11-18 02:47:36

根据您拥有的 Eclipse 版本,从 Eclipse Marketplace 安装 m2e 和 subclipse。然后:

  1. 打开 Eclipse 进入 Window >开放视角>其他...>> SVN 存储库探索
  2. 将您的 svn url 添加到 SVN 存储库/代码库。
  3. 选择一个项目。右键单击并选择结帐
  4. 假设您的项目有一个 pom.xml,切换回 Java 视角,选择刚刚导入的项目,右键单击并选择 Configure >转换为 Maven 项目

现在它应该被识别为 Maven 和 Java 项目(Maven 和 Java 性质将被添加到 Eclipse .project 文件中)

Install m2e and subclipse from the Eclipse Marketplace depending on what version of Eclipse you have. Then:

  1. Open Eclipse go to Window > Open Perspective > Other... > SVN Repository Exploring.
  2. Add your svn url to SVN repository/code base.
  3. Select a project. Right Click and select Checkout.
  4. Assuming your project has a pom.xml, switch back to your Java perspective, select the project that was just imported, right click and select Configure > Convert to Maven Project.

It should now be recognized as both a Maven and a Java project (Maven and Java natures will have been added to the Eclipse .project file)

丑丑阿 2024-11-18 02:47:36

只需从我的工作区中删除该项目,删除所有 .project、.classpath 文件和 .settings 文件夹,然后重新导入即可解决问题。我不知道为什么第一次没有成功。谢谢大家的帮助。

Problem was solved simply by deleting the project from my workspace, deleting all .project, .classpath files and .settings folders, and re-importing. I don't know why it didn't work the first time. Thanks for the help, everyone.

小草泠泠 2024-11-18 02:47:36

右键单击项目-->属性-->行家 -->生命周期映射 -->检查(跳过maven编译器插件)单击“确定”,现在构建路径出现。 nw 进行必要的更改

right click project --> properties --> maven --> lifecycle mapping --> check (skip maven compiler plugin) click ok now the build path appears . nw do the necessary changes

兔小萌 2024-11-18 02:47:36

我陷入了类似的情况,但我意识到,由于我试图在父集合中进行更改,因此您无法找到 eclipse intellisense,因为它只是保存项目。尝试使用 Maven 创建的专有项目。

I got stuck in similar situation but I realized that since I am trying to change in the parent collection you cannot find eclipse intellisense due to the fact that it is just holding the projects. Try working on exclusive project created by maven.

左岸枫 2024-11-18 02:47:36

检查pom.xml文件中的打包标签。

当我将 pom.xml 更改为使用时,它起作用了:

<packaging>jar</packaging>

Check the packaging tag in the pom.xml file.

It worked when I changed pom.xml to use:

<packaging>jar</packaging>
凌乱心跳 2024-11-18 02:47:36

确保 POM 没有任何错误,Eclipse 根据初始构建(自动或手动)检测项目类型。

Make sure that POM doesn't have any error, Eclipse detecting the project types based on the initial build (automatically or manual).

离鸿 2024-11-18 02:47:36

项目性质由 Eclipse 中的 .project 文件决定,该文件还向 Eclipse 指示有关父源代码和测试文件夹的信息。

按如下方式更新/修改 .project 文件,使用该文件我们保留项目的 Maven 兼容性和 Java 性质。

Eclipse项目文件夹下的.project.xml

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>java-cgdk-en</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>org.eclipse.jdt.core.javabuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>  
        <natures>
                <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
</projectDescription>

The Project nature is decided by the .project file in Eclipse, which also dictates to Eclipse about the Parent Source Code, and Test Folders.

Update/Modify the .project file as follows, using which We retain the Maven Compatibility and Java Nature of the Project.

.project.xml under the Eclipse Project folder

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>java-cgdk-en</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>org.eclipse.jdt.core.javabuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>  
        <natures>
                <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
</projectDescription>
墨洒年华 2024-11-18 02:47:36

对于 Eclipse 2022-06 (4.24.0),上述方法都不适合我。然而,它确实做到了:

https://www.youtube.com/watch?v=aF0xP9SXcrE - 如何解决子模块未识别为 Maven 项目的问题

希望这会有所帮助。

With Eclipse 2022-06 (4.24.0), none of the above worked for me. However, this did:

https://www.youtube.com/watch?v=aF0xP9SXcrE - How to resolve Child module not recognized as maven project

Hope this helps.

九公里浅绿 2024-11-18 02:47:36

请尝试清理您的 Eclipse

eclipse.exe -clean

如果它不适合您,

尝试安装新的 Eclipse 并导入相同的项目更新:

无需安装新的 Eclipse,只需在 eclipse.ini 文件中恢复您的 vm 参数(如果您已经更改了它)

try to clean your eclipse

eclipse.exe -clean

if it's not work for you try to install a new eclipse and imposrt the same project

Update :

No need to install a new Eclipse just revert your vm args in eclipse.ini file if you already change it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文