mirror of
https://github.com/FranzHaidnor/haidnorJVM.git
synced 2026-03-24 23:23:44 +08:00
add 支持从 jmods 中读取文件. 废弃 rt.jar 配置项
This commit is contained in:
@@ -4,10 +4,10 @@ import haidnor.jvm.rtda.Klass;
|
|||||||
import org.apache.bcel.classfile.ClassParser;
|
import org.apache.bcel.classfile.ClassParser;
|
||||||
import org.apache.bcel.classfile.JavaClass;
|
import org.apache.bcel.classfile.JavaClass;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
@@ -18,19 +18,18 @@ public class ClassLoader {
|
|||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
|
|
||||||
public final static String rtJarPath;
|
public final static String JAVA_HOME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.base.jmod 文件路径
|
||||||
|
*/
|
||||||
|
public final static String javaBaseJmodPath;
|
||||||
|
|
||||||
public JarFile jarFile = null;
|
public JarFile jarFile = null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
InputStream is = ClassLoader.class.getResourceAsStream("/haidnorJVM.properties");
|
JAVA_HOME = System.getenv( "JAVA_HOME");
|
||||||
Properties properties = new Properties();
|
javaBaseJmodPath = JAVA_HOME + "/jmods/java.base.jmod";
|
||||||
try {
|
|
||||||
properties.load(is);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
rtJarPath = properties.getProperty("rt.jar");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassLoader(String name) {
|
public ClassLoader(String name) {
|
||||||
@@ -48,10 +47,7 @@ public class ClassLoader {
|
|||||||
public Klass loadClass(String classPath) throws IOException {
|
public Klass loadClass(String classPath) throws IOException {
|
||||||
ClassParser classParser = null;
|
ClassParser classParser = null;
|
||||||
if (classPath.startsWith("java/")) {
|
if (classPath.startsWith("java/")) {
|
||||||
if (!new File(rtJarPath).exists()) {
|
classParser = new ClassParser(javaBaseJmodPath, "classes/" + classPath + ".class");
|
||||||
throw new IllegalStateException("rt.jar not found");
|
|
||||||
}
|
|
||||||
classParser = new ClassParser(rtJarPath, classPath + ".class");
|
|
||||||
} else if (jarFile != null) {
|
} else if (jarFile != null) {
|
||||||
Enumeration<JarEntry> entries = jarFile.entries();
|
Enumeration<JarEntry> entries = jarFile.entries();
|
||||||
while (entries.hasMoreElements()) {
|
while (entries.hasMoreElements()) {
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ public class TestJVM {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void demo_foreach_2() throws Exception {
|
public void demo_foreach_2() throws Exception {
|
||||||
// TODO wangxiang fix bug
|
|
||||||
// runMainClass(demo_foreach_2.class);
|
// runMainClass(demo_foreach_2.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
rt.jar=D:/Program Files/Java/jdk1.8.0_361/jre/lib/rt.jar
|
|
||||||
Reference in New Issue
Block a user