Srikanth M
Srikanth M

Reputation: 105

NoClassDefFoundError at runtime in java project using maven

I've a maven java projects (say X & Y) and i've added Y to dependency list of the project X (pom file) and imported Y to class in X... and jars are installed to m2 repositorhy and maven build is successful with no errors at compilation, but at runtime it is thorwing a NoClassDefFoundError for the class in Y... am new to this maven please help me to resolve the issue..

java.lang.NoClassDefFoundError: ../nw_diagnosis/SocketExceptionHandler

Thanks Srikanth

Upvotes: 2

Views: 2164

Answers (3)

Samuel EUSTACHI
Samuel EUSTACHI

Reputation: 3156

Is your X project a "jar" project, or a "war" project ?

If you build a jar, your Y project (I assume this one is a jar) is not included in the classpath of your X project, which is the normal behavior.

If so, you either have to run your X project with Y.jar in the classpath, or build your X project as a "jar-with-dependencies", see below :

http://www.springone2gx.com/blog/scott_leberknight/2008/06/creating_executable_jars_using_the_maven_assembly_plugin

Upvotes: 2

Stephen C
Stephen C

Reputation: 718688

I suspect this is a problem with an optional dependency in one of the artifacts that your application depends on.

Anyway, the general approach to solving this is:

  • figure out what class is missing based on the exception message,
  • figure out what JAR file contains or should contain the missing class,
  • figure out what the maven group/artifact/version corresponds to the missing JAR, and
  • add the corresponding dependency to your project's POM file.

Upvotes: 1

Andrew T Finnell
Andrew T Finnell

Reputation: 13628

Are you building on command line, then trying to run in Eclipse? M2e doesn't like that. Clean and rebuild all your projects from within eclipse then try running.

Upvotes: 0

Related Questions