【问题标题】:Why does the maven eclipse plugin break the maven jetty plugin?为什么maven eclipse插件会破坏maven jetty插件?
【发布时间】:2011-01-15 23:48:58
【问题描述】:

我想让 maven eclipse 插件在每次运行构建时重新生成我的 .classpath,我通过使用以下配置来实现:

    <!--
        Generate a new .classpath each time the build is run, but don't try
        to download sources or javadocs
    -->
    <profile>
        <id>elipse-update</id>
        <activation>
            <file>
                <exists>.classpath</exists>
            </file>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>eclipse</goal>
                            </goals>
                            <configuration>
                                <downloadSources>false</downloadSources>
                                <downloadJavadocs>false</downloadJavadocs>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

由于某种原因,这会导致 maven jetty 插件因 ClassNotFoundException 错误而失败(它抱怨各种 Spring 类不存在)。当然,当我没有安装 maven eclipse 插件时,它可以正常工作。这是我所说的一个例子:

$ mvn jetty:run
[INFO] Scanning for projects...
...
[INFO] Starting jetty 6.1.22 ...
2010-02-11 20:53:08.984:INFO::jetty-6.1.22
2010-02-11 20:53:09.109:WARN::Could not instantiate listener org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195)
        at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255)
        at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:274)
        at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

当然,如果我删除那个 eclipse 插件部分,我可以按预期运行 jetty:

$ mvn jetty:run
[INFO] Scanning for projects...
...
Feb 11, 2010 8:55:28 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 1672 ms
2010-02-11 20:55:28.687:INFO::Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 5 seconds.

我知道的一些事情:

  • 是的,我只在 .classpath 存在时才激活此配置文件。这似乎违反直觉,但我有一个理由:我有另一个配置文件在 .classpath 不存在时激活,它运行 eclipse 插件,下载源代码和 javadocs 的选项设置为 true。我不希望每次构建都发生这种情况,因此我为类路径已经存在时创建了一个单独的插件配置。
  • 是的,我可以简单地创建包含我希望更改的选项值的属性,而不是再次指定整个插件配置。在这种情况下,我只需根据类路径的存在情况将 eclipse.downloadSources 属性设置为 true 或 false,并在常规构建部分中有一个插件定义。

有什么建议吗?这是一个奇怪的问题。

谢谢, LES

【问题讨论】:

    标签: eclipse maven-2 jetty maven-jetty-plugin


    【解决方案1】:

    我怀疑 Maven Eclipse 插件 mess 做了一些类路径木偶,这会影响以后的码头插件。

    但老实说,这并不是使用 Eclipse 插件的一种非常常见的方式,至少据我所知不是。大多数人不会在他们的构建中包含它,他们只是在 POM 发生更改时运行它,而且这通常不会在每个构建中发生。此外,如果我记得很清楚,触摸.classpath 会使 Eclipse 感到困惑,并强制重新构建项目,这很烦人。

    所以最后,我很抱歉,这似乎带来了更多的烦恼而不是好处。不过你可以尝试打开Jira issue

    【讨论】:

    • 我已经包含了一个插件配置,它只会在 .classpath 丢失时运行 eclipse:eclipse。这样我可以告诉人们检查源代码,运行 mvn install 并且他们的类路径将为他们提供。我暂时禁用了始终开启的配置,因为它不起作用。每当我更改 pom 文件时,必须记住运行 eclipse:eclipse 是一种痛苦——我希望使用 maven 自动发生这种情况(我没有版本控制下的 .classpath,因为它是从 maven 派生的)
    • @LES2 我理解,但遗憾的是,它不起作用(你会记得在 pom 更改时运行它,尤其是在出现一些此类错误之后)。另一种选择是使用 m2eclipse 插件,这将解决这个问题(在导入项目之前必须运行任何东西)。我很长时间以来一直是 maven-eclipse-plugin 的用户,但几个月前就换了,到目前为止我很满意。
    • 我已经尝试过 eclipse 插件,但对它没有印象:减慢了 eclipse 的速度并且不稳定。也许我没有正确配置它。 :/ 我想我会记录一个 JIRA 以防万一有人想修复它:(
    • @LES2 毫无疑问,m2eclipse 不能像 maven-eclipse-plugin 那样轻量级。虽然我同意它不是很被动(这就是为什么我没有使用它,因为我不需要花哨的 pom 编辑器或向导),但我发现现在情况好多了。但我不能说它确实加速了 Eclipse。我想这是获得更好集成的代价(我需要过滤支持)。不过,我仍然经常收到 StackOverflowError,非常烦人。
    • 我想我会指出,现在 M2E 插件非常好,不应该减慢 Eclipse 的速度。 eclipse:eclipse 现在已经过时了,IMO。
    【解决方案2】:

    当存在 .classpath 时,您真的不想在每次构建时都运行 maven-eclipse-plugin。我不能确切地告诉你它对类路径做了什么,但这不是它的用途。假设当您运行它时,您只运行 eclipse:eclipse(或其他目标)。

    为什么要继续重新运行它?

    【讨论】:

    • 我只是想让其他开发人员在更改 pom 文件时更容易;目前,当我更改某些内容时,我必须告诉他们运行 mvn eclipse:eclipse;否则,他们会在 eclipse 中遇到各种红色错误,并且由于 maven 构建工作,他们不会费心去弄清楚它们;这会导致他们忽略所有真正好的警告 - 例如,空指针访问等。如果我能让 eclipse 始终保持最新,我希望人们会更加关注 elcipse 警告;自动化对此有所帮助。 :)
    • 根据@Pascal Thivent 的说法,Jira 可能是您最好的选择。或者,看看您是否可以安装配置文件激活以确保在 jetty 插件打开时将其关闭?
    • 如果我没记错的话,它也会破坏 cobertura 仪器......所以我必须继续排除插件,因为发现更多问题......我想我可以记录一个 JIRA,所以至少开发人员已经意识到这一点(如果他们还没有意识到)
    猜你喜欢
    • 2011-01-31
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    • 2011-04-24
    • 2012-01-05
    相关资源
    最近更新 更多