10

I have two Vaadin projects (I will name them A and B). Both are using Maven for resolving the dependencies and are in the same workspace. I'm working with Eclipse and I'm using the m2e-plugin. I want to use some classes of B in project A. In Eclipse I can instatiate them without errors/warnings but when I try to run A I get a ClassNotFoundException and a NoClassDefFoundError caused by instatiating a class of B.

The .class files of A are located in ...\workspace\A\target\classes and the for project B they are in ...\workspace\B\target\classes. I've been trying to solve this problem but I didn't find a solution. What I tried so far:

  • Configure build path -> Libaries -> add Class Folder -> B\target
  • Configure build path -> Libaries -> add External Class Folder -> B\target
  • Configure build path -> Projects -> add -> B

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

I don't have any idea what else to do. Maybe I have to configure my pom.xml file but I don't know what I must 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 did clean compile for project B with maven build. Then I tried to do the same with project A but then I get 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 normally I still get the ClassNotFoundException and NoClassDefError.

Edit 2: I have added

<scope>compile</scope>

When I run Maven build (clean compile), part of my building process looks like this:

[INFO] Building centwertAdmin 0.0.1-SNAPSHOT

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

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

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

[INFO] BUILD FAILURE

Then there is the errormessage:

[ERROR] Failed to execute goal on project centwertAdmin: Could not resolve dependencies for project de.qufis:centwertAdmin:war:0.0.1-SNAPSHOT: Failure to find de.qufis:CentwertApp:war:0.0.1-SNAPSHOT in http://maven.vaadin.com/vaadin-addons was cached in the local repository, resolution will not be reattempted until the update interval of vaadin-addons has elapsed or updates are forced -> [Help 1]

Stoney
  • 397
  • 1
  • 2
  • 13
  • can u try to remove war from B? plus, do u have B in the dependencies of A? – OhadR Nov 24 '15 at 22:11
  • This is similar to http://stackoverflow.com/questions/10188495/how-to-use-class-file-from-another-war/43338653#43338653 – Ruthwik Apr 11 '17 at 07:20

1 Answers1

6

can u try to remove <packaging>war</packaging> from B? Maven's default packaging is jar, and this is what you need for B.

Plus, add B to the dependencies of A.

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

Usually, dependencies are of type JAR. If B must be a WAR, see this.

Community
  • 1
  • 1
OhadR
  • 8,276
  • 3
  • 47
  • 53
  • I stillt get the same mistake when I try to do Maven build (clean compile) in porject A. I get this warning: `[WARNING] The POM for de.qufis:CentwertApp:jar:0.0.1-SNAPSHOT is missing, no dependency information available`. CentwertApp is project B. I allready added B to the dependecies of A – Stoney Nov 24 '15 at 22:29
  • edited the answer... is it working now? i saw that you marked @Tunaki's answer as "accepted" – OhadR Nov 24 '15 at 23:01
  • Do i have to build it as a jar file? or do i just have to build it and verify that it is in my local repository. And i just tried to mark @Tunaki's answer as useful but it didnt work so i accepted it ;) – Stoney Nov 25 '15 at 01:14
  • yes. build it as a jar and follow the steps i mentioned. let me know if it helps. – OhadR Nov 25 '15 at 06:24
  • I did maven build (clean package) for project B. So I got a jar file which i copied into .m2 folder. But when i do maven build (clean compile) for project A i still get the message that the pom.xml for project B is missing. – Stoney Nov 25 '15 at 20:38
  • 1
    i bet you did not copy it to the correct place... rather than mvn build, try to run mvn install. that will let maven copy the JAR+POM to the correct place in your local repo (.m2). – OhadR Nov 26 '15 at 06:08