How to get the full classpath info

B

bill_j_chen

Hi, Java guru,

I am in a situation that I need to figure out which *.jar files the
java process is using. Basically this huge J2EE application has a lot
of customized jar files (hundreds jar files). We are troubleshooting an
application issue and suspect a wrong jar file (same name) is being
used instead of the expected one.

Here comes the question. after the java process is running, how can we
know the full classpath which the process uses to find the class it is
looking for?

Platform: Solaris
JDK: 1.5

Thanks.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

I am in a situation that I need to figure out which *.jar files the
java process is using. Basically this huge J2EE application has a lot
of customized jar files (hundreds jar files). We are troubleshooting an
application issue and suspect a wrong jar file (same name) is being
used instead of the expected one.

Here comes the question. after the java process is running, how can we
know the full classpath which the process uses to find the class it is
looking for?

It is very difficult to know for sure.

But below are a small JSP file that may give you some ideas.

Arne

<%@ page import="java.net.*" %>
<ul>
<%
ClassLoader cl = this.getClass().getClassLoader();
while(cl != null) {
%>
<li><%=cl.getClass().getName()%></li>
<%
if(cl instanceof URLClassLoader) {
%>
<ul>
<%
URL[] urls = ((URLClassLoader)cl).getURLs();
for(int i = 0; i < urls.length; i++) {
%>
<li><%=urls%></li>
<%
}
%>
</ul>
<%
}
cl = cl.getParent();
}
%>
</ul>
 
M

Manish Pandit

You can also try <%=System.getProperty("java.class.path")%> in the JSP.

-cheers,
Manish
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Manish said:
You can also try <%=System.getProperty("java.class.path")%> in the JSP.

That will not return useful information in a J2EE context, because
most of the interesting stuff are loaded by classloaders created
by the app server.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top