使用 Maven 为 Eclipse 设置项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1397903/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:59:56  来源:igfitidea点击:

Setting project for eclipse using maven

eclipsemaven-2

提问by egaga

I'm trying to start modifying an existing application with Eclipse. Actually I had it working before, but I deleted the project, and now with "mvn eclipse:eclipse" I get the following:

我正在尝试开始使用 Eclipse 修改现有应用程序。实际上我之前有它的工作,但我删除了该项目,现在使用“mvn eclipse:eclipse”我得到以下信息:

[INFO] Resource directory's path matches an existing source directory. Resources will be merged with the source directory src/main/resources
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Request to merge when 'filtering' is not identical. Original=resource src/main/resources: output=target/classes, include=[atlassian-plugin.xml], exclude=[**/*.java], test=false, filtering=true,
 merging with=resource src/main/resources: output=target/classes, include=[], exclude=[atlassian-plugin.xml|**/*.java], test=false, filtering=false
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Request to merge when 'filtering' is not identical. Original=resource src/main/resources: output=target/classes, include=[atlassian-plugin.xml],
 exclude=[**/*.java], test=false, filtering=true, merging with=resource src/main/resources: output=target/classes, include=[], exclude=[atlassian-plugin.xml|**/*.java], test=false, filtering=false
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:583)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Request to merge when 'filtering' is not identical. Original=resource src/main/resources: output=target/classes, include=[atlassian-plugin.xm
l], exclude=[**/*.java], test=false, filtering=true, merging with=resource src/main/resources: output=target/classes, include=[], exclude=[atlassian-plugin.xml|**/*.java], test=false, filtering=false
        at org.apache.maven.plugin.eclipse.EclipseSourceDir.merge(EclipseSourceDir.java:302)
        at org.apache.maven.plugin.eclipse.EclipsePlugin.extractResourceDirs(EclipsePlugin.java:1605)
        at org.apache.maven.plugin.eclipse.EclipsePlugin.buildDirectoryList(EclipsePlugin.java:1490)
        at org.apache.maven.plugin.eclipse.EclipsePlugin.createEclipseWriterConfig(EclipsePlugin.java:1180)
        at org.apache.maven.plugin.eclipse.EclipsePlugin.writeConfiguration(EclipsePlugin.java:1043)
        at org.apache.maven.plugin.ide.AbstractIdeSupportMojo.execute(AbstractIdeSupportMojo.java:511)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
        ... 16 more

回答by VonC

Would this make it better?

这会让它变得更好吗?

 mvn org.apache.maven.plugins:maven-eclipse-plugin:2.6:eclipse

This tells maven to use version 2.6 (which still works) instead of the default 2.7 (which doesn't).
You'll have to issue the command like this every time, so it's a little inconvenient whereas the file changes above should result in a one-time fix, but this way you don't risk accidentally breaking something else and you don't have to go looking for files.
If you can't remember the command syntax, copy it into a text file for easier reference.

这告诉 maven 使用版本 2.6(仍然有效)而不是默认的 2.7(无效)。
您每次都必须发出这样的命令,因此有点不方便,而上面的文件更改应该会导致一次性修复,但是这样您就不会冒险意外破坏其他东西并且您没有去找文件。
如果您不记得命令语法,请将其复制到文本文件中以便于参考。

See this thread.

看到这个线程

It does mention a recent change in the Maven Eclipse Plugin:

它确实提到了 Maven Eclipse 插件的最新变化:

回答by Rich Seller

I think VonC's answer is the right one (+1) if you are using the eclipse:eclipse goal. Personally I find it more trouble than it's worth and instead use m2eclipse to manage the dependencies, committing the eclipse metadata files to SCM.

如果您使用 eclipse:eclipse 目标,我认为 VonC 的答案是正确的(+1)。我个人觉得它比它的价值更麻烦,而是使用 m2eclipse 来管理依赖项,将 eclipse 元数据文件提交给 SCM。

To avoid having to invoke eclipse:eclipse with the fully-qualified name as VonC suggests, you can configure the plugin in your pom to use the exact version. This is good practiceanyway.

为了避免使用 VonC 建议的完全限定名称调用 eclipse:eclipse,您可以在 pom 中配置插件以使用确切版本。无论如何,这是一个很好的做法

In the pom, specify the plugin as follows:

在pom中,指定插件如下:

<build>
...
  <plugins>
  ...
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-eclipse-plugin</artifactId>
      <version>2.6</version>
    </plugin>
  </plugins>
</build>

Then whenever you invoke the eclipse plugin, version 2.6 will be used.

然后,无论何时调用 eclipse 插件,都将使用 2.6 版。

回答by Romain Linsolas

Can we have a look to the pom.xml of the project?

可以看看项目的pom.xml吗?

Did you try to run the mvn clean eclipse:clean eclipse:eclipsecommand?

您是否尝试运行该mvn clean eclipse:clean eclipse:eclipse命令?