I'm trying to create an Eclipse project that runs a locally patched version of rt.jar
. By local, I mean local to the Eclipse project. The Eclipse project contains a folder called runtimes
, which contains a copy of the default runtime jars. I've set the project's classpath to use these library jars and not the system jars (using IJavaProject.setRawClasspath).
The Eclipse project has a single test class.
import java.io.File;
public class POC {
public static void main(String[] args) {
System.out.println("File Resource:");
ClassLoader loader = POC.class.getClassLoader();
System.out.println(loader.getResource("java/io/File.class"));
System.out.println("\nLibrary Path:");
String librarypath = System.getProperty("java.library.path");
String[] librarypathEntries = librarypath.split(File.pathSeparator);
for(String lp : librarypathEntries){
System.out.println(lp);
}
System.out.println("\nClasspath:");
String classpath = System.getProperty("java.class.path");
String[] classpathEntries = classpath.split(File.pathSeparator);
for(String cp : classpathEntries){
System.out.println(cp);
}
}
}
Currently it prints something to the effect of...
File Resource:
jar:file:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/rt.jar!/java/io/File.class
Library Path:
/Users/ben/Library/Java/Extensions
/Library/Java/Extensions
/Network/Library/Java/Extensions
/System/Library/Java/Extensions
/usr/lib/java
.
Classpath:
/Users/ben/.../workspace/Test/runtimes/resources.jar
/Users/ben/.../workspace/Test/runtimes/rt.jar
/Users/ben/.../workspace/Test/runtimes/jsse.jar
/Users/ben/.../workspace/Test/runtimes/jce.jar
/Users/ben/.../workspace/Test/runtimes/charsets.jar
/Users/ben/.../workspace/Test/runtimes/jfr.jar
/Users/ben/.../workspace/Test/runtimes/JObjC.jar
/Users/ben/.../workspace/Test/runtimes/dnsns.jar
/Users/ben/.../workspace/Test/runtimes/localedata.jar
/Users/ben/.../workspace/Test/runtimes/sunec.jar
/Users/ben/.../workspace/Test/runtimes/sunjce_provider.jar
/Users/ben/.../workspace/Test/runtimes/sunpkcs11.jar
/Users/ben/.../workspace/Test/runtimes/zipfs.jar
/Users/ben/.../workspace/Test/runtimes/MRJToolkit.jar
/Users/ben/.../workspace/Test/bin
Since apparently setting the classpath isn't enough, I tried editing the Run Configurations
and setting a few variations of the VM argument for -Xbootclasspath as suggested by this article.
Example: -Xbootclasspath/p:/Users/.../workspace/Test/runtimes/rt.jar;
This seemed to have no effect on the File Resource output (it always loads the original implementation of File).
I also tried -Djava.library.path=/Users/ben/.../Test/runtimes/
, but that didn't change the File Resource either.
I'm wondering if it's related to this question.
P.S. I know applications that override a class in the rt.jar file are a violation of the Java SE run-time environment binary code license. This is not for production use, I just want to see it working.