classloader

Why java newInstance hang at getDeclaredConstructors0?

孤者浪人 提交于 2020-08-08 06:40:20
问题 We use mozlia rhino to generate dynamic class, then load JsClass by custom classloader like this DynamicClassLoader loader = new DynamicClassLoader(JavaScriptFactory.class.getClassLoader()); Class<?> jsClass = loader.loadClass("D://","com.huawei.xxx"); jsClass.newInstance(); As you see, every JsClass have a seperate classloader, when user modify js, we will also reload JsClass by this code, Now, we face a problem, when call jsClass.newInstance(), some thread hang at getDeclaredConstructors0

Why ClassLoader returns a path with extraneous second exclamation point

走远了吗. 提交于 2020-07-22 21:33:35
问题 I'm trying to grab a resource in ClassLoader . A simplified version of the code looks something like this: String ePath = "rewrite/common/RenameFunctor.groovy" String fPath = ThClType.class.getClassLoader().getResource(ePath); the response I get back as fPath is jar:file:/Users/myName/warPath/warName.war!/WEB-INF/classes!/rewrite/common/RenameFunctor.groovy . The actual path to the resource we want it exactly that, except without the second exclamation point. (Unlike warName.war , classes is

Custom ClassLoader, how to use?

為{幸葍}努か 提交于 2020-05-27 05:36:09
问题 I am trying to use a custom class loader to load all the dependencies needed for the application. I've implemented the customerClassLoader following the site: https://www.javacodegeeks.com/2013/03/java-handmade-classloader-isolation.html However, I dont understand how to tell my application to use the custom classLoader whenever needed. For instance: Lets say, I have a method to make http request like below. How can I tell the application to use the custom classLoader to load the required

Java: Where does the Extensions Class Loader get classes from in Java 13?

早过忘川 提交于 2020-05-23 09:54:24
问题 All the documentation I've been able to find mentions the 'jre/lib/ext' folder but such does not exist on my JRE 13 installation. I guess somewhere between Java 8 (where I can see the jars in jre/lib/ext) and Java 13, they moved but I've been unable to pinpoint when and how it was done. Could someone please elaborate what's going on with new JRE's, in terms of where the extension classes reside currently? 回答1: The extension mechanism is gone with Java 9, not only moved [:-| , see the

Java: Where does the Extensions Class Loader get classes from in Java 13?

非 Y 不嫁゛ 提交于 2020-05-23 09:54:17
问题 All the documentation I've been able to find mentions the 'jre/lib/ext' folder but such does not exist on my JRE 13 installation. I guess somewhere between Java 8 (where I can see the jars in jre/lib/ext) and Java 13, they moved but I've been unable to pinpoint when and how it was done. Could someone please elaborate what's going on with new JRE's, in terms of where the extension classes reside currently? 回答1: The extension mechanism is gone with Java 9, not only moved [:-| , see the

Which ClassLoader should I supply to Proxy.newProxyInstance(…)?

好久不见. 提交于 2020-05-11 04:38:05
问题 I have read the documentation, but I still don't understand which classloader I should supply as an argument. I've tried a few options, but this seems to have no effect on compilation or the behavior of the proxy. It is a little unsettling that I can pass anything as the class loader argument, including null , and the code still works fine. Can anyone explain this, and tell me what kind of errors can arise if I provide a bad argument for the classloader? I should add that I don't really have

java.lang.StringIndexOutOfBoundsException: String index out of range when package name is changed

牧云@^-^@ 提交于 2020-04-30 06:30:37
问题 I want to read the annotations from .class file placed into random folder. I tried this: public static void main(String[] args) throws Exception { final File folder = new File("/opt/test"); processAnnotatedFiles(listLocalFilesAndDirsAllLevels(folder)); } public void processAnnotatedFiles(List<File> list) throws IOException, ClassNotFoundException { out.println("Directory files size " + list.size()); for(int i=0; i<list.size(); i++) { out.println("File " + list.get(i).getName()); File file =

Class.forName(name, instantiation, classLoader) doesn't add class to classpath

那年仲夏 提交于 2020-04-12 06:02:07
问题 I'm generating .java class files at the runtime and need to utilize those classes inside the code instantly. So I compile the .java classes using Compiler API to make .class files: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); StandardJavaFileManager manager = compiler.getStandardFileManager(diagnostics, null, null); File file = new File("path to file"); Iterable<? extends JavaFileObject> sources =

Class.forName(name, instantiation, classLoader) doesn't add class to classpath

房东的猫 提交于 2020-04-12 06:01:46
问题 I'm generating .java class files at the runtime and need to utilize those classes inside the code instantly. So I compile the .java classes using Compiler API to make .class files: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); StandardJavaFileManager manager = compiler.getStandardFileManager(diagnostics, null, null); File file = new File("path to file"); Iterable<? extends JavaFileObject> sources =