1

I want to make sure that a JAR won't throw NoClassDefinitionFound exception before it is deployed to a server. More advanced requirement is to be able to specify additional class paths.

How this can be done?

humkins
  • 9,635
  • 11
  • 57
  • 75

1 Answers1

0

In general it is not possible since your JAR file can load classes dynamically using Class.forName() or ClassLoader.loadClass() methods

I would say that the proper approach is to use some dependency management tool during your build process which will assemble all the dependencies for you.

Maven war plugin will do it for you automatically

bedrin
  • 4,458
  • 32
  • 53
  • JVM must be able to extract Class.forName() and ClassLoader.loadClass() calls and FQNs passed to them from bytecode, right? In that case why other tool can't? – humkins May 13 '15 at 08:09
  • Cause in general the actual values are known only in runtime - the web application itself is a good example: application server doesn't know what classes to load until it parses web.xml or scans the jars for annotations – bedrin May 13 '15 at 08:11