更改 Eclipse 项目以使用 Maven?
我的老板要求我将我们的一个项目转换为使用 Maven 来构建。所以我创建了一个 pom.xml 文件,现在 Maven 可以很好地构建项目并运行所有测试和所有内容。 “好吧”,我的老板说,“我们不再需要这些了”,然后他从项目中删除了 /libs 目录,并从类路径中删除了 JRE。没关系,它仍然在 Maven 中构建,但 Eclipse 将 jre 或 /libs 中的所有内容显示为编辑器中未解析的内容。由于所有错误指示,我正在认真考虑回到 vi。我怎样才能得到它,以便 Eclipse 可以完成它的工作?
My boss asked me to convert one of our projects to use Maven to build. So I created a pom.xml file and now Maven builds the project fine and runs all the tests and everything. "Fine", my boss said, "We don't need these any more" and he deleted the /libs directory from the project, and he deleted the JRE from the classpath. That's fine, it still builds in Maven, but Eclipse shows everything that was in the jre or in /libs as unresolved in the editor. Because of all the error indications, I'm seriously considering going back to vi. How can I get it so Eclipse can do its thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要创建 Eclipse
.classpath
和.project
文件,请执行以下操作:这将创建对本地 Maven 存储库的引用,这意味着您必须至少构建使用 Maven 一次,以便它可以下载文件。我相信您还必须定义一个 Eclipse 类路径变量
M2_REPO
(至少,我定义了一个,并且看不出我这样做的任何其他原因)。我假设您的老板从 Eclipse 类路径中删除了 JRE 条目,这很愚蠢,但不像删除实际的 JRE 目录那么愚蠢。 Maven 构建类路径文件应包含适当的内容,或者您可以进入“构建路径”对话框并通过“库”选项卡添加 JRE。
To create the Eclipse
.classpath
and.project
files, do the following:This will create references to your local Maven repository, which means that you'll have to build at least once with Maven, so that it can download the files. I believe you also have to define an Eclipse classpath variable
M2_REPO
(at least, I have one defined, and can't see any other reason I'd have done that).I'll assume your boss deleted the JRE entry from the Eclipse classpath, which was dumb but not as dumb as deleting your actual JRE directory. The Maven-build classpath file should include something appropriate, or you can go into the "Build Path" dialog and add the JRE via the "Libraries" tab.
哦,没关系 - 我点击了“Maven->启用依赖管理”并修复了它。不知道为什么我之前没有想到。
Oh never mind - I clicked the "Maven->Enable dependency management" and that fixed it. Don't know why I didn't think of it before.
使用 Maven-Eclipse 插件。
Use a Maven-Eclipse plugin.
您可以像 Nick 提到的那样使用插件,但您也可以通过将 eclipse 指向本地 Maven 存储库来非常简单地解决这个问题。
1) 在工作区中创建一个类路径变量 M2_REPO。它应该指向类似“c:\Document and Settings\yourname.m2repo\
2)添加您需要的罐子。
这些步骤也可以使用 mvn eclipse:eclipse goal 自动化。文档位于此处,我在过去但在定制它时遇到了一些困难(对于项目中 /.settings/ 文件夹下的 WTP 和 Spring 配置文件)
You can use plugins as Nick mentions, but you can also solve this very simply by pointing eclipse to your local maven repository.
1) create a classpath variable, M2_REPO, in your workspace. It should point to something like "c:\Document and Settings\yourname.m2repo\
2) Add the jars that you need.
These steps can also be automated with mvn eclipse:eclipse goal as well. The docs are here, I used it in the past but had some difficulties customizing it (for WTP and Spring configuration files under /.settings/ folder in the project)