how to change default classloader by a command-line argument to the JVM v6
.....or some other means that are completely external to the Java program (the classloader can be changed at runtime by the program itself, but that's not what I am looking for).
I've heard it could be done for the IBM
JVM, but I'm looking for the exact way for the Sun JVM.
Thanks .
[312 byte] By [
towstta] at [2007-11-27 6:16:18]

I've tried it , and have discovered an additional problem .
What should be the constructior of my new class loader ?
Here is the code of all classes :
******************************
public class TestClass { }
*****************************
*********************************
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class MyClassLoader extends ClassLoader {
public static final String HELLO_WORLD = "TestClass" ;
public MyClassLoader () {
super(ClassLoader.getSystemClassLoader().getParent()) ;
}
public Class findClass(String name) throws ClassNotFoundException {
try {
InputStream in = ClassLoader.getSystemResourceAsStream (
name.replace('.','/') + ".class");
byte[] buffer = new byte[100000] ;
int len = in.read(buffer);
byte[] cf = new byte[len];
System.arraycopy(buffer,0,cf,0,len);
if (name.equals(HELLO_WORLD))
System.out.println("It works");
return defineClass(name,cf,0,cf.length);
} catch (Exception e) {
throw new ClassNotFoundException (HELLO_WORLD) ;
}
}
}
**************************************
****************************************
public class HelloWorld {
public static void main(String[] args) {
TestClass test ;
System.out.println("Hello world") ;
}
}
************************************************
I've tried the following command :
java -Djava.system.class.loader=MyClassLoader HelloWorld
Here is the error i've got :
Error occurred during initialization of VM
java.lang.Error: java.lang.NoSuchMethodException: MyClassLoader.<init>(java.lang
.ClassLoader)
at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
Caused by: java.lang.NoSuchMethodException: MyClassLoader.<init>(java.lang.Class
Loader)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at java.lang.SystemClassLoaderAction.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
Would the command succeed I would expect the following result :
It works
Hello World
I understand that MyClassLoader constructor is wrong since I am trying to get parent of SystemClassLoader which is now MyClassLoader itself and not the 'old regular' SystemClassLoader , but how can I get it now to properly initialize my class loader ?
Thanks .