简体   繁体   中英

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:

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

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. (java.lang.NoClassDefFoundError)

I think it might be a bug in the maven eclipse plugin, someone has any idea that can be happening?

Workaround is described on 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. 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. 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.

My simple answer is the following link to the bug tracking system of Eclipse:

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

See the answers inside.

Yes it's a problem with Eclipse itself..

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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