This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to which class is loaded from which jar file alongwith location?

 
Danish Sualeh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
please look at the following code :

import org.apache.commons.lang.*;
public class test
{
public static void main(String Args[])
{
System.out.println(StringEscapeUtils.escapeHtml("bootstrap classloader: ")
+ String.class.getClassLoader());
}
}


When I run the compiled class, i want to know which class is being loaded from which jar and its location.
Using java -verbose solves the problem partially because it show only info about natives jars and classes of J2SE package.
But what about the external jars (commons-lang-2.1.jar)
and their classes ?
 
Thomas Bigbee
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this will be of any help, if it is not, I apologize.

I use Eclipse 3.1 (which is free), putting my mouse over a fragment of code will usually give me back some pretty verbose information. Example:

Hovering the mouse over getLogger

Logger.log = Logger.getLogger(TestClient);

will give me "Logger org.apache.log4j.Logger.getLogger(String arg0)"

This tells me the Object, Method, Package and Arguments.

I know this is not run-time, and you don't get the jar or the jar's directory, however, since you have to add each jar to the Project and you can expand the jar and the package in the Package Explorer View, you know where everything is comming from, moreover, ambigous package class referneces are not allowed (wont compile until fixed).

With that said, one of the biggest reasons I moved from Textpad to Eclipse was the ability to debug conflicting class names, not that it happened very often, however, when it did, it took forever to find the offending jar.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic