Maven Dependency Error in Eclipse

I have an artifact of war, and I need to use some of their classes from the can. 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 lead to the deployment of two artifacts: mywebapp-1.0-SNAPSHOT.war and mywebapp-1.0-SNAPSHOT-classes.jar.

To use these classes, I refer to the artifact as follows:

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

When I compile from Jenkins, everything works correctly, but when I run tests locally from Eclipse, I cannot find reference classes. (Java.lang.NoClassDefFoundError)

I think this might be a bug in the maven eclipse plugin, does anyone have an idea that could happen?

+6
source share
2 answers

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

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

See the answers inside.

Yes, this is a problem with Eclipse itself ..

The solution in Eclipse simply adds the project manually to the workspace in the corresponding project, where you need classes from your military project.

+4
source

A workaround is described at http://wiki.eclipse.org/M2E-WTP_FAQ :

A workaround exists, but we need to change the dependency on whether the project is built in Eclipse or not. In a 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, in other circumstances it is ignored. In this case, only the dependent project will use an empty classifier to refer to the web project, which will be added to the class path, as expected.

+5
source

Source: https://habr.com/ru/post/914734/


All Articles