Reputation: 2128
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??
Upvotes: 4
Views: 12105
Reputation: 2128
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.
Upvotes: 0
Reputation: 570295
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?
Upvotes: 7
Reputation: 84028
Maven resolves dependencies from local and remote repositories, though IDE plugins such as m2eclipse will also resolve dependencies that are projects within the workspace. If you don't have such a plugin, you will need to install artifact Y to a local repository or deploy it to a remote repository so that you and your peers can access it before Maven will recognise that a change has been made when building project X.
If the two projects are closely related, you could consider creating a multi-module build so that projects X and Y are built at the same time.
Upvotes: 0
Reputation: 139921
Did you install/deploy the new version of Y, upgrade X's dependencies for the new Y version, and re-build X?
Upvotes: 0