简体   繁体   English

Eclipse中的Maven依赖项错误

[英]Maven Dependency error in Eclipse

I have a war artefact and I need use some of their classes from a jar. 我有一个战争文物,我需要从罐子里使用他们的一些类。 I can't move the classes to another project, then I deploy the classes and resources included in my webapp as an "attached" artifact using the following configuration: 我无法将类移动到另一个项目,然后使用以下配置将我的webapp中包含的类和资源部署为“附加”工件:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <attachClasses>true</attachClasses>
    </configuration>
</plugin>

This will result in two artifacts being deployed: mywebapp-1.0-SNAPSHOT.war and mywebapp-1.0-SNAPSHOT-classes.jar. 这将导致部署两个工件:mywebapp-1.0-SNAPSHOT.war和mywebapp-1.0-SNAPSHOT-classes.jar。

To use those classes I Referencing the artifact as follows: 要使用这些类,我将引用工件,如下所示:

    <dependency>
        <groupId>mygroup</groupId>
        <artifactId>mywebapp</artifactId>
        <version>${project.version}</version>
        <classifier>classes</classifier>
    </dependency>

When I compiled from Jenkins everything works correctly, but when I run the tests locally from Eclipse can not find the reference classes. 当我从Jenkins编译时一切正常,但是当我从Eclipse本地运行测试时找不到引用类。 (java.lang.NoClassDefFoundError) (java.lang.NoClassDefFoundError)

I think it might be a bug in the maven eclipse plugin, someone has any idea that can be happening? 我认为它可能是maven eclipse插件中的一个错误,有人有任何想法可以发生吗?

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

A workaround exists though, we need to change the dependency whether the project is built in Eclipse or not. 但是存在一种解决方法,我们需要更改依赖项,无论项目是否在Eclipse中构建。 In your dependent project, you can configure the following : 在依赖项目中,您可以配置以下内容:

<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>

The m2e profile is automatically activated when the project is built with m2e, ignored in other circumstances. 当使用m2e构建项目时,m2e配置文件会自动激活,在其他情况下会被忽略。 In that case only, the dependent project will use an empty classifier to reference the web project, which will be added to the classpath as expected. 仅在这种情况下,依赖项目将使用空分类器来引用Web项目,该项目将按预期添加到类路径中。

My simple answer is the following link to the bug tracking system of Eclipse: 我的简单答案是Eclipse的bug跟踪系统的以下链接:

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

See the answers inside. 看看里面的答案。

Yes it's a problem with Eclipse itself.. 是的,Eclipse本身就是一个问题。

The solution within Eclipse just add the project manually within your workspace to the appropriate project where you need the classes out of your war project. Eclipse中的解决方案只是在您的工作区中手动将项目添加到您需要战争项目中的类的相应项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM