How can I use classes from another project with maven? (A ClassNotFoundException and NoClassDefFoundError are thrown)

I have two Vaadin projects (let's call them A and B). Both use Maven to resolve dependencies and are in the same workspace. I work with Eclipse and I use the m2e plugin. I want to use some classes B in project A. In Eclipse, I can install them without errors / warnings, but when I try to start AI, get a ClassNotFoundException and a NoClassDefFoundError caused by setting class B.

The .class A files are located in ...\workspace\A\target\classes , and for project B they are located in ...\workspace\B\target\classes . I tried to solve this problem, but I did not find a solution. What I have tried so far:

  • Configure build path -> Libaries -> add class folder -> B \ target
  • Configure build path -> Libaries -> add external class folder -> B \ target
  • Set build path β†’ Projects β†’ Add β†’ B

I think adding a project is necessary because when I delete it, Eclipse gives me error messages when I try to use classes from B to A

I do not know what else to do. Perhaps I need to configure the pom.xml file, but I do not know what to do there.

Edit: In pom.xml of project B:

 <groupId>de.qufis</groupId> <artifactId>CentwertApp</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>CentwertApp</name> 

In pom.xml of project A:

  <dependency> <groupId>de.qufis</groupId> <artifactId>CentwertApp</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> <scope>import</scope> </dependency> 

I cleaned the compilation for project B using maven build. Then I tried to do the same with project A, but then I get the error message: Could not find artifact de.qufis: CentwertApp: war: 0.0.1-SNAPSHOT in vaadin-addons ( http://maven.vaadin.com / vaadin-addons )

When I run the application, I still get a ClassNotFoundException and a NoClassDefError.

Edit 2: I added

 <scope>compile</scope> 

When I run the Maven build (pure compilation), part of my build process is as follows:

[INFO] Building centwertAdmin 0.0.1-SNAPSHOT

[INFO] -------------------------------------------- --- -------------------------

[WARNING] POM for de.qufis: CentwertApp: war: 0.0.1-SNAPSHOT missing, dependency information not available

[INFO] -------------------------------------------- --- -------------------------

[INFO] STRICT FAULT

Then an errormessage occurs:

[ERROR] The target in the centwertAdmin project could not be completed: the dependencies for the de.qufis project: centwertAdmin: war: 0.0.1-SNAPSHOT could not be resolved: The de.quis: CentwertApp: war: 0.0.1-SNAPSHOT could not be found in http: //maven.vaadin.com/vaadin-addons has been cached in the local repository, the permission will not be reloaded until the vaadin-addons update interval has expired or the update has been forced to update β†’ [Help 1]

+7
java eclipse maven
source share
1 answer

Can I try to remove <packaging>war</packaging> from B? The default packaging is Maven jar , and this is what you need for B.

Also, add B to the dependencies file A.

  • Build project B. use mvn clean install to install B JAR + POM in your local repository (.m2).
  • Confirm that there is ... Then Maven will be able to find it, so you will not get the error "Could not find the artifact de.qufis: CentwertApp"
  • Assembly A.

Dependencies are usually of type JAR. If B should be WAR, see this .

+4
source share

All Articles