导入Eclipse IDE后如何构建和运行Maven项目 [英] How to build and run Maven projects after importing into Eclipse IDE

查看:47
本文介绍了导入Eclipse IDE后如何构建和运行Maven项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习使用 Maven 在 Eclipse 中构建 Java 项目.我从
创建了一个Java项目HelloWorldD:/maven_projects 文件夹中的maven-archetype-quickstart"模板.然后为了将 Maven 项目转换为支持 Eclipse IDE,我导航到项目文件夹并发出命令:
mvn eclipse:eclipsemvn package .

I am learning building a Java project in Eclipse using Maven. I created a Java project HelloWorld from
"maven-archetype-quickstart" template in a folder D:/maven_projects. Then to convert the Maven project to support Eclipse IDE, I navigated into the project folder and issued the commands:
mvn eclipse:eclipse and mvn package .

然后我将项目导入到 Eclipse 中,并进行了必要的 Eclipse 配置,例如在 Eclipse 类路径中设置 Maven 本地存储库.现在该项目位于 D:/EclipseWorkspace 文件夹中.我在 Eclipse 打印helloworld"中成功运行了该项目.

Then I imported the project in Eclipse and did the necessary Eclipse configurations like setting the Maven local repository in Eclipse classpath. Now the project in D:/EclipseWorkspace folder. I ran the project successfully in Eclipse printing "helloworld".

现在如果我想继续开发该项目并且因此想在 Eclipse 的 pom.xml 中添加新的依赖项,则不会添加新的 jar在我运行项目时的类路径中.

Now if I want to go on develop the project and for that reason want to add new dependencies in pom.xml in Eclipse, then the new jars are not added in classpath when I run the project.

所以我的问题是在将 Maven 项目导入 Eclipse 后,如何在 pom.xml 中添加越来越多的依赖项,然后构建并运行该项目?推荐的有效方法是什么?

So my question is after importing a Maven project into Eclipse how can I add more and more dependencies in pom.xml, then build and run the project? What is the recommended and efficient way to do this?

推荐答案

我建议您不要使用 m2eclipse 命令行工具(即 mvn eclipse:eclipse),而是使用内置的-在 Maven 支持中,称为 m2e.

I would recommend you don't use the m2eclipse command line tools (i.e. mvn eclipse:eclipse) and instead use the built-in Maven support, known as m2e.

从 Eclipse 中删除您的项目,然后在您的项目上运行 mvn eclipse:clean 以删除 m2eclipse 项目数据.最后,使用现代版本的 Eclipse,只需执行Import > Maven > Existing project into workspace..."并选择您的 pom.xml.

Delete your project from Eclipse, then run mvn eclipse:clean on your project to remove the m2eclipse project data. Finally, with a modern version of Eclipse, just do "Import > Maven > Existing project into workspace..." and select your pom.xml.

M2e 将自动管理您的依赖项并根据需要下载它们.它还通过新的Run as Maven build..."接口支持 Maven 构建.还挺漂亮的.

M2e will automatically manage your dependencies and download them as required. It also supports Maven builds through a new "Run as Maven build..." interface. It's rather nifty.

这篇关于导入Eclipse IDE后如何构建和运行Maven项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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