views:

449

answers:

3

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?

A: 

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.

Kevin Williams
I'm not running on the CLI, but instead inside a Java program. Does this bug still apply? My classpath is 13465 letters long.
André Neves
possibly - if you're running Java on windows. It's just a guess, but we've run into it a few times due to the large number of jars and maven-like naming conventions. I haven't seen the issue on *nix machines. Do you have any more error details?
Kevin Williams
If you're running from a war it should load all jars that you have in your lib folder by default unless you have something loading on container startup that has dependancies that aren't being met.
Kevin Williams
Dismissed. Ran some tests, and it's not it.
André Neves
Do you have a stack trace or configuration details?
Kevin Williams
A: 

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");

Nicolas
No, it's not a problem with the JARs.
André Neves
A: 
JRL
All the JARs are explicitly included. Can't be that.
André Neves
I'd try unjar-ing those jars and providing the class directly in the classpath instead of just the jar. I'm guessing that it's all because of the Manifest file entries - i.e that the manifest has entries for the class names themselves and not the jars.
JRL
If that fails, I'd also try changing the path to a folder without spaces in it such as "C:\Temp" to see if that fixes the problem.
JRL