views:

818

answers:

6

Hi all,

I have a Java project X has dependency (in pom file) on project Y.

I was modifying in Y and build X,Y with Maven tool then runing X (on JBoss) without problems.

When I added new class in Y then building with Maven (without problems), then running X, it throws java.lang.NoClassDefFoundError for the new class.

I think its a Maven dependency versioning or something like that ... I searched mainly at Google but nothing has effect... How to resolve this problem??

A: 

Did you run mvn install on Y after adding the new class?

Jim Downing
yes I did it with mvn install
Moro
A: 

Did you install/deploy the new version of Y, upgrade X's dependencies for the new Y version, and re-build X?

matt b
the Y pom has version <version>1.0</version> and the X pom has the dependency as <dependency> <groupId>Y</groupId> <artifactId>Y</artifactId> <scope>provided</scope> <version>1.0</version> </dependency>
Moro
A: 

Did you try mvn clean on project Y before you built it?

hoffmandirt
yes clean then install for Y ... and clean then package for X
Moro
A: 
Rich Seller
1. It is in repository, such that i use install command 2. It already a multi-module project ... and I tried to build it within the parent project ... but the same thing
Moro
+4  A: 

Moro, you wrote in a comment that X has the following dependency declared:

<dependency>
  <groupId>Y</groupId>
  <artifactId>Y</artifactId>
  <scope>provided</scope>
  <version>1.0</version>
</dependency>

First point. You are using a "fixed" version here (as opposed to "SNAPSHOT"). When using SNAPSHOT, maven will automatically grab the latest SNAPSHOT every time you build. On the other hand, when you are using 1.0, once maven has downloaded this artifact, it never tries to get a new 1.0. So, you should increment Y's version or, if Y is under active development (enhancements, bug fixes, etc), you should really use SNAPSHOT. For more informations about SNAPSHOT, check out the chapter 9.3.1.2. SNAPSHOT Versions of Sonatype's book:

Why would you use this? SNAPSHOT versions are used for projects under active development. If your project depends on a software component that is under active development, you can depend on a SNAPSHOT release, and Maven will periodically attempt to download the latest snapshot from a repository when you run a build. Similarly, if the next release of your system is going to have a version "1.4", your project would have a version "1.4-SNAPSHOT" until it was formally released.

Second point. You are using a provided scope. According to the chapter 9.4.1. Dependency Scope:

provided dependencies are used when you expect the JDK or a container to provide them. For example, if you were developing a web application, you would need the Servlet API available on the compile classpath to compile a servlet, but you wouldn’t want to include the Servlet API in the packaged WAR; the Servlet API JAR is supplied by your application server or servlet container. provided dependencies are available on the compilation classpath (not runtime). They are not transitive, nor are they packaged.

Is this really what you want? How are you deploying X and Y on JBoss? Shouldn't you use the default compile scope?

Pascal Thivent
I just used <dependency> <groupId>Y</groupId> <artifactId>Y</artifactId> <version>1.0-SNAPSHOT</version> </dependency> but it didn't put lib directory and not running
Moro
that is because you need to change the versionnumber in Y to 1.0-SNAPSHOT and then run mvn install. after that, the correct dependency is available
Salandur
no man, I already did it
Moro
@Moro Without more details about your maven modules (packaging, versions...), it's hard to guess what is exactly happening. What kind of J2EE module is X? What kind of packaging are you using in your pom.xml? Could you provide your pom.xml files?
Pascal Thivent
you both updated the version number in Y\pom.xml and the reference to it in X\pom.xml ?
matt b
A: 

Ok, sorry for late info.

The X package is ejb, so the X.jar has no lib directory.

Then Y.jar should be placed in the Jboss/server/default/lib, it worked correctly.

Thanx for all.

Moro