导入到Eclipse IDE后如何构建和运行Maven项目 [英] How to build and run Maven projects after importing into Eclipse IDE
问题描述
中的
maven-archetype-quickstart模板创建了一个Java项目 HelloWorld
D:/ maven_projects 。然后转换Maven项目以支持Eclipse IDE,我导航到项目文件夹并发出命令:
mvn eclipse:eclipse
和 mvn package
。
然后我在Eclipse中导入了项目,并进行了必要的Eclipse配置,例如在Eclipse类路径中设置Maven本地存储库。现在在 D:/ EclipseWorkspace
文件夹中的项目。我在Eclipse打印helloworld中成功运行了该项目。
现在如果我想继续开发项目,为此,希望在 pom.xml中添加新的依赖关系在Eclipse中,那么当我运行项目时,新的jar不会添加到classpath中。
所以我的问题是在将Maven项目导入Eclipse后,如何在pom.xml中添加越来越多的依赖项,然后构建并运行项目?推荐和有效的方法是什么?
解决方案我建议您不要使用m2eclipse命令行工具即 mvn eclipse:eclipse
),而是使用内置的Maven支持,称为 m2e 。
从Eclipse中删除项目,然后在项目中运行 mvn eclipse:clean
m2eclipse项目数据。最后,使用Eclipse的现代版本,只需将Import>Maven>现有项目添加到工作空间...并选择您的pom.xml。
M2e将自动管理您的依赖关系并根据需要下载。它还通过新的Run as Maven build ...界面支持Maven构建。这很漂亮。
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
.
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".
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.
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?
解决方案 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.
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 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屋!