Frage

I am trying to apply patch using classpath approach, I mean I am adding modified class files as jar file, and while classes are getting loaded new version of classes are loaded. Therefore application is patched without changing original jar file.

The following classpath definition works fine;

java -cp patch/patch.jar;bin/  com.test.PatchClasspath

but when order of lib classes are changed it does not work.(as usual)

java -cp bin/;patch/patch.jar  com.test.PatchClasspath

I would like to know is there a JVM parameter which indicates the lib loading order?

EDITED: I amd modifying Util->print() method to verify patch is applied.

package com.test;

public class PatchClasspath {

public static void main(String[] args) {
    Util util = new Util();
    util.print();
}   

}


package com.test;

public class Util {


public void print(){
    System.out.println("Version-1");
}

}

Thanks.

War es hilfreich?

Lösung

There is no such parameter indicate the lib loading order in JVM (I believe), however, the java -classpath option itself will determine the class loading order base on the paths you put.

JDK document explain this: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/classpath.html

Specification order

The order in which you specify multiple class path entries is important. The Java interpreter will look for classes in the directories in the order they appear in the class path variable. In the example above, the Java interpreter will first look for a needed class in the directory C:\java\MyClasses. Only if it doesn't find a class with the proper name in that directory will the interpreter look in the C:\java\OtherClasses directory.

Andere Tipps

Try -verbose:class, this will show you all the loaded classes, in which order they were loaded and from which jar they were loaded.

To control the order of classes loaded, you can modify the order of jars in your classpath, using the java -cp. I do not think there is a way howto control the order of classes being loaded from a specific jar.

To verify that the patch is applied, a simple/dummy solution is to add a static field with the System.out.println(""). For Example:

static {
  System.out.println("[DBG] : My Patch v1.0 is loaded.");
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top