Adding -verbose in the startWebLogic.sh script does not really tell you
which classloader loaded the class.
One way I was thinking was to use the methods in java.lang.ClassLoader. But
it has no way to get the CURRENT classloader ( like get the EJB or servlet
classloader ), only the system classloader, and you have no way of getting
child classloaders from the system classloader either.
# java ... ShowClassLoaders ... weblogic.Server
ShowClassLoaders.java
---------------------
import java.io.*;
import java.util.*;
import com.sun.jdi.*;
import com.sun.jdi.connect.*;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;
public class ShowClassLoaders {
static final String[] excludes = {
"java.*",
"javax.*",
"sun.*",
"com.sun.*",
"weblogic.*"
};
public static void main(String[] args) {
try {
VirtualMachine vm = null;
LaunchingConnector connector = null;
for(Iterator i = Bootstrap.virtualMachineManager().allConnectors().iterator(); i.hasNext(); ) {
Connector c = (Connector)i.next();
if (c.name().equals("com.sun.jdi.CommandLineLaunch")) {
connector = (LaunchingConnector)c;
}
}
Map arguments = connector.defaultArguments();
Connector.Argument mainArgument = (Connector.Argument)arguments.get("main");
StringBuffer mainArgs = new StringBuffer();
int i;
for(i = 0; i < args.length - 1; i++) {
mainArgs.append(args[i] + " ");
} mainArgs.append(args[i]);
mainArgument.setValue(mainArgs.toString());
vm = connector.launch(arguments);
EventRequestManager erm = vm.eventRequestManager();
ClassPrepareRequest cpr = erm.createClassPrepareRequest();
for(i = 0; i < excludes.length; i++) {
cpr.addClassExclusionFilter(excludes[i]);
}
cpr.enable();
Thread eventsListener = new DisplayClassLoaders(vm.eventQueue());
Process p = vm.process();
new WebLogicOutput(p.getErrorStream());
new WebLogicOutput(p.getInputStream());
vm.resume();
eventsListener.join();
} catch(Throwable oops) {
oops.printStackTrace();
}
}
private static class DisplayClassLoaders extends Thread {
EventQueue eventQueue;
public DisplayClassLoaders(EventQueue eventQueue) {
super();
this.eventQueue = eventQueue;
start();
}
public void run() {
try {
boolean stop = false;
do {
EventSet eventSet = eventQueue.remove();
for(EventIterator i = eventSet.eventIterator(); i.hasNext(); ) {
Event evt = i.nextEvent();
if(evt instanceof ClassPrepareEvent) {
ClassPrepareEvent cpe = (ClassPrepareEvent)evt;
ReferenceType refType = cpe.referenceType();
System.out.println("Loading:" + refType.name() +
", " + refType.classLoader());
} else if(evt instanceof VMDisconnectEvent) {
stop = true;
}
}
eventSet.resume();
} while(!stop);
} catch(Throwable oops) {
oops.printStackTrace();
}
}
}
static private class WebLogicOutput extends Thread {
InputStreamReader in;
OutputStreamWriter out = new OutputStreamWriter(System.out);
public void run() {
try {
int i;
char[] buf = new char[256];
while ((i = in.read(buf, 0, buf.length)) >= 0) {
out.write(buf, 0, i);
}
} catch(Throwable oops) {
oops.printStackTrace();
}
}
public WebLogicOutput(InputStream in) {
super();
this.in = new InputStreamReader(in);
setDaemon(true);
start();
}
}
}
--
Dimitri
com.sun.jdi.VMDisconnectedException: Socket closed
at com.sun.tools.jdi.TargetVM.send(TargetVM.java:260)
at
com.sun.tools.jdi.VirtualMachineImpl.sendToTarget(VirtualMachineImpl.java:685)
at com.sun.tools.jdi.PacketStream.send(PacketStream.java:44)
at
com.sun.tools.jdi.JDWP$VirtualMachine$Resume.enqueueCommand(JDWP.java:603)
at
com.sun.tools.jdi.VirtualMachineImpl$1.send(VirtualMachineImpl.java:280)
at com.sun.tools.jdi.VMState.thawCommand(VMState.java:97)
at
com.sun.tools.jdi.VirtualMachineImpl.resume(VirtualMachineImpl.java:284)
at ShowClassLoaders.main(ShowClassLoaders.java:56)
Thanks anyway.
I had to put "-classpath $CLASSPATH" after ShowClassLoaders and before
weblogic.server
...
C:\bea\wlserver>C:\java\bin\java -classpath .;c:\java\lib\tools.jar ShowClassLoaders -classpath
.;.\lib\weblogic_sp.jar;.\l
ib\weblogic.jar;.\samples\eval\cloudscape\lib\cloudscape.jar;.\config\examples\serverclasses
-Dweblogic.Domain
=examples -Dweblogic.Name=examplesServer -Dbea.home=C:\bea
-Dcloudscape.system.home=./samples/eval/cloudscape/data weblogic.Server
Loading:com.bea.utils.misc.ProcessBase, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:com.bea.utils.misc.ProcessException, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:com.bea.utils.misc.ProcessException2, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:com.bea.utils.misc.InvalidProcessException, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:weblogicx.xml.version, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:com.bea.utils.misc.ProcessManager, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:com.bea.utils.misc.ProcessFileNotFoundException, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:org.xml.sax.EntityResolver, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:org.xml.sax.DTDHandler, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:org.xml.sax.ContentHandler, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:org.xml.sax.ErrorHandler, instance of sun.misc.Launcher$AppClassLoader(id=119)
Loading:org.xml.sax.helpers.DefaultHandler, instance of sun.misc.Launcher$AppClassLoader(id=119)
...
Loading:examples.ejb.subclass.ParentBean, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
Loading:examples.ejb.subclass.ChildBean, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
Loading:examples.ejb.subclass.ChildHome, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
Loading:examples.ejb.subclass.Parent, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
Loading:examples.ejb.subclass.Child, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
Loading:examples.ejb.subclass.ChildBeanHomeImpl, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
Loading:examples.ejb.subclass.ChildBeanImpl, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
Loading:examples.ejb.subclass.ChildBeanEOImpl, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
Loading:examples.ejb.subclass.ChildBeanEOImpl_WLStub, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
Loading:examples.ejb.subclass.ChildBeanHomeImpl_WLStub, instance of weblogic.utils.classloaders.GenericClassLoader(id=3461)
...
####<May 29, 2001 7:06:40 PM PDT> <Notice> <WebLogicServer> <pooh> <examplesServer> <main> <system> <> <000216>
<WebLogic Server started>
...
> Thanks anyway.
> Dimitri Rakitine wrote:
--
Dimitri