Eclipse+Maven 编译问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1417890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse+Maven compile problem
提问by Avi Y
currently, I am developing web-apps using Eclipse. The build is done using Maven. The problem is that during compile time Eclipse is showing a lot of errors since there are a lot of missing jars. The final result is OK since the Maven is responsible for fetching these jars.
目前,我正在使用 Eclipse 开发 Web 应用程序。构建是使用 Maven 完成的。问题是在编译期间 Eclipse 显示了很多错误,因为有很多丢失的 jars。最终结果是可以的,因为 Maven 负责获取这些 jar。
How can make the eclipse not fail the compilation?
怎样才能让eclipse不编译失败?
I know I can just add the missing jars to the project classpath, but that's not what I'm looking for because I have a lot of projects, and the .classpath file of each project is a file common to all developers, so I would rather not to change it.
我知道我可以将缺少的 jar 添加到项目类路径中,但这不是我要找的,因为我有很多项目,而且每个项目的 .classpath 文件是所有开发人员通用的文件,所以我会而不是去改变它。
My question is therefor, is there a way to add a common classpath to all Eclipse projects without changing each project's classpath?
因此,我的问题是,有没有办法在不更改每个项目的类路径的情况下向所有 Eclipse 项目添加通用类路径?
回答by Rich Seller
I use m2eclipse. It adds a classpath container to the .classpath file. This container is populated with the Maven dependencies by a Maven builder (added to the .project when the Maven nature is enabled) which processes the POM and downloads any artifacts (and sources if needed).
我使用m2eclipse。它将类路径容器添加到 .classpath 文件。该容器由 Maven 构建器(在启用 Maven 性质时添加到 .project 中)填充 Maven 依赖项,该构建器处理 POM 并下载任何工件(如果需要,还下载源)。
To enable the Maven nature (assuming the plugin is installed), right-click on a project and select Enable Dependency Management.
要启用 Maven 特性(假设已安装插件),请右键单击一个项目并选择Enable Dependency Management。
By default m2eclipse uses an embedded version of Maven to do its processing. This typically means a separate local repository and duplicate files on the box. You can configure it to use your standard Maven installation in Window->Preferences->Maven->Installations. Then adding the path to your Maven installation (normally the same as M2_HOME).
默认情况下,m2eclipse 使用嵌入式版本的 Maven 进行处理。这通常意味着一个单独的本地存储库和盒子上的重复文件。您可以在 Window->Preferences->Maven->Installations 中将其配置为使用您的标准 Maven 安装。然后将路径添加到您的 Maven 安装(通常与 M2_HOME 相同)。
There is another Maven plugin for Eclipse called IAM(formerly called Q4E). IAM is an Eclipse integration project and has some promising features - it's worth keeping an eye on.
Eclipse 有另一个 Maven 插件,称为IAM(以前称为 Q4E)。IAM 是一个 Eclipse 集成项目,有一些很有前途的特性——值得关注。
There is a comparison of the Eclipse Maven integrations, alongside the maven-eclipse-plugin(a goal that generates the Eclipse metadata files from the POM contents). I personally find the maven-eclipse-plugin more trouble than it's worth but it may suit your purposes and it is handy for generating the initial metadata if you have none checked into the SCM.
有一个Eclipse Maven 集成与maven-eclipse-plugin(一个从 POM 内容生成 Eclipse 元数据文件的目标)的比较。我个人认为 maven-eclipse-plugin 比它的价值更麻烦,但它可能适合您的目的,如果您没有签入 SCM,它可以方便地生成初始元数据。