Version Control Maven and java.lang.NoClassDefFoundError

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

I changed to Y and built X, Y with the Maven tool, and then run X (on JBoss) without any problems.

When I added a new class to Y and then built with Maven (no problem), then ran X, he selected java.lang.NoClassDefFoundError for the new class.

I think this is a version of Maven version control or something like that ... I searched mainly Google, but nothing affected ... How to solve this problem?

+4
source share
6 answers

Ok, sorry for the late info.

The X package is ejb, so X.jar does not have a lib directory.

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

Thanx for everyone.

0
source

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

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

First point. Here you use the "fixed" version (as opposed to the " SNAPSHOT "). When using SNAPSHOT maven automatically captures the last SNAPSHOT every time you create. On the other hand, when you use 1.0, once maven has downloaded this artifact, it never tries to get a new 1.0. Thus, you should increase the Y-version or, if Y is in active development (improvements, bug fixes, etc.), you really should use SNAPSHOT . For more information about SNAPSHOT see Section 9.3.1.2. Versions of the SNAPSHOT Sonatip Book:

Why would you use this? Snapshot versions are used for active development projects. If your project depends on a software component that is being actively developed, you may depend on the release of SNAPSHOT and Maven will periodically try to download the last snapshot from when you start the build. Similarly, if the next release of your system has a version of "1.4", your project will have a version of "1.4-SNAPSHOT" until it has been officially released.

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

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

Is this really what you want? How do you post X and Y on JBoss? Shouldn't the default compile area be used?

+7
source

Did you run mvn install in Y after adding a new class?

0
source

Have you installed / deployed a new version of Y, updated the X dependencies for the new version of Y, and rebuilt X?

0
source

Did you try to run mvn clean on project Y before you created it?

0
source

Maven allows dependencies on local and remote repositories, although IDE plugins such as m2eclipse will also allow dependencies that are projects in the workspace. If you do not have such a plugin, you will need to install the Y artifact in the local repository or deploy it to the remote repository so that you and your peers can access it before Maven finds out that the changes were made when creating the X project.

screenshot of the workspace http://docs.codehaus.org/download/attachments/11403480/project-properties.png

If the two projects are closely related, you might consider creating a multi-module assembly so that projects X and Y are built at the same time.

0
source

All Articles