Classpath problems with Jini ClassDep, Java's dependency finder

1.4k Views Asked by At

I started to use Sun's ClassDep as a solution to fight the inclusion of unnecessary JARs in my resulting WAR application. It seems to rock. However, this beast is hard to tame!

I'm getting several errors of classes not found even if they are explicitly included in the classpath I pass to it. Example:

couldn't find: org.apache.log4j.Logger: No file for: Logger
couldn't find: org.hibernate.Session: No file for: Session
couldn't find: org.joda.time.LocalDate: No file for: LocalDate

HOWEVER... Check out a piece of the classpath I'm giving it:

...;"C:\Documents and Settings\Andre\Desktop\workspace\icaro\WebContent\WEB-INF\lib\hibernate3.jar";...;"C:\Documents and Settings\Andre\Desktop\workspace\icaro\WebContent\WEB-INF\lib\joda-time-1.5.2.jar";"C:\Documents and Settings\Andre\Desktop\workspace\icaro\WebContent\WEB-INF\lib\log4j-1.2.11.jar";...

I went through those and saw that the "missing" classes are actually in those files.

Anyone got any idea what gives?

3

There are 3 best solutions below

5
On

I see you are running on windows. Could you be running into the infamous "Input line it too long" exception?

It's possible your Classpath is too long if you're including a large number of jar files.

This post by Hung Huynh (Terracotta) has a better explanation of the issue and a couple of options for how you can handle it if this is the problem you're having.

1
On

Couldn't it be a problem with your jars? Typically, if it's a classpath problem, you would get a NoClassDefFoundError.

Some ways to investigate this would be

  1. display the classpath from your program (System.out.println(System.getProperty("java.class.path");

  2. ask the class loader to display the URL of a loaded class at various point of your application if you're using a hierarchy of classloaders (System.out.println(Thread.currentThread().getContextClassLoader().getResource( "org/apache/log4j/Logger.class");

3
On

Those entries are probably in the manifest files of one or more JARS that you reference. Manifest files entries are ignored by Classdep and so will give you errors.

See ClassDep documentation:

If you use JAR files, any Class-Path manifest entries in those JAR files are ignored, so you must include the values of those manifest entries explicitly in the path, or errors may result. For example, if you include jini-ext.jar then you should explicitly include jini-core.jar as well, because jini-core.jar is in the Class-Path manifest entry of jini-ext.jar.