Eclipse中的Maven依赖项错误

Die*_*o D 7 java maven

我有一个战争人工制品,我需要从罐子里使用他们的一些类.我无法将类移动到另一个项目,然后使用以下配置将我的webapp中包含的类和资源部署为"附加"工件:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <attachClasses>true</attachClasses>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

这将导致部署两个工件:mywebapp-1.0-SNAPSHOT.war和mywebapp-1.0-SNAPSHOT-classes.jar.

要使用这些类,我将引用工件,如下所示:

    <dependency>
        <groupId>mygroup</groupId>
        <artifactId>mywebapp</artifactId>
        <version>${project.version}</version>
        <classifier>classes</classifier>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

当我从Jenkins编译时一切正常,但是当我从Eclipse本地运行测试时找不到引用类.(java.lang.NoClassDefFoundError)

我认为它可能是maven eclipse插件中的一个错误,有人有任何想法可以发生吗?

K E*_*son 5

解决方法在http://wiki.eclipse.org/M2E-WTP_FAQ上描述:

但是存在一种解决方法,我们需要更改依赖项,无论项目是否在Eclipse中构建.在依赖项目中,您可以配置以下内容:

<dependencies>
 ...
 <dependency>
   <groupId>com.company</groupId>
   <artifactId>mywebapp</artifactId>
   <version>1.0.0-SNAPSHOT</version>
   <classifier>${webClassifier}</classifier>
 </dependency>
 ...
</dependencies>
...
<properties>
 ...
 <webClassifier>classes</webClassifier>
</properties>
...
<profiles>
 <profile>
   <id>m2e</id>
   <activation>
     <property>
       <name>m2e.version</name>
     </property>
   </activation>
   <properties>
     <webClassifier></webClassifier>
   </properties>
 </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

当使用m2e构建项目时,m2e配置文件会自动激活,在其他情况下会被忽略.仅在这种情况下,依赖项目将使用空分类器来引用Web项目,该项目将按预期添加到类路径中.


khm*_*ise 4

我的简单回答是以下 Eclipse 错误跟踪系统的链接:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=365419

请参阅里面的答案。

是的,这是 Eclipse 本身的问题。

Eclipse 中的解决方案只需在工作区中手动将项目添加到需要 war 项目中的类的适当项目中。