0

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?

Community
  • 1
  • 1
André Chalella
  • 13,788
  • 10
  • 54
  • 62

3 Answers3

0

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
  • 2,588
  • 3
  • 24
  • 25
  • 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é Chalella Apr 23 '09 at 18:18
  • 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 Apr 24 '09 at 06:56
  • 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 Apr 24 '09 at 07:01
  • Dismissed. Ran some tests, and it's not it. – André Chalella Apr 24 '09 at 20:51
  • Do you have a stack trace or configuration details? – Kevin Williams Apr 26 '09 at 04:36
0

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 C
  • 944
  • 1
  • 10
  • 22
0

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.

JRL
  • 76,767
  • 18
  • 98
  • 146
  • All the JARs are explicitly included. Can't be that. – André Chalella Apr 24 '09 at 20:55
  • 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 Apr 24 '09 at 23:42
  • 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 Apr 24 '09 at 23:43