classloader

Create Classloader with only classes inside specific folder

时光怂恿深爱的人放手 提交于 2019-12-07 15:53:51
问题 I want to load specific jars in ScriptEngineManager using specific ClassLoader This constructor loads the implementations of ScriptEngineFactory visible to the given ClassLoader using the service provider mechanism. The problem when I tried to create Classloader File file = new File("c:\\myclasses\\"); try { // Convert File to a URL URL url = file.toURI().toURL(); // file:/c:/myclasses/ URL[] urls = new URL[]{url}; // Create a new class loader with the directory ClassLoader cl = new

Same native library loaded by different class loader

为君一笑 提交于 2019-12-07 15:26:25
问题 Please consider the following scenario: I have two java classes, loaded using different system class loaders. I have a native library that has a queue implemented. Both the classes will load the same library, and add elements to the queue. Is it possible? If so, will the native library implementation be shared across the two classes.? 回答1: According to the JNI Specification it is not possible. In the JDK, each class loader manages its own set of native libraries. The same JNI native library

Can java string literals be garbage collected?. If Yes, how to prove it?

≡放荡痞女 提交于 2019-12-07 13:35:43
问题 Can java String literals like "abc" be garbage collected?. If yes, how can we programatially prove that they are GCed? 回答1: Yes, post Java7, String literals can be garbage collected if the class loader which loaded it gets garbage collected and there are no references to the string literal. Note : In Java -8, you will have to call GC twice in order to ensure that ClassLoaders get GCed (Metaspace.. pfff..Using a different GC won't help). Case -1 : //ClassLoaders don't get GCed. Code : import

Where and when is the instance of PathClassLoader created in android source code?

戏子无情 提交于 2019-12-07 12:24:26
问题 When I was studying android source code, I noticed that the general class loader in app is an instance of PathClassLoader , and there is two constructors in this class. One is like: public PathClassLoader(String dexPath, ClassLoader parent) { super(dexPath, null, null, parent); } and the other is like: public PathClassLoader(String dexPath, String libraryPath, ClassLoader parent) { super(dexPath, null, libraryPath, parent); } But I cannot find the call of the second constructor in the source

How to scan JAR's, which are loaded at runtime, with Google reflections library?

不想你离开。 提交于 2019-12-07 09:41:16
问题 Is there a solution to configure the reflection library so that it scans also JAR's which are added at runtime with URLClassLoader? For now, reflections just scans the URLs in the ClassLoader. This is the configuration which I am using now: Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader())); I couldn't find any hints in the doc of the reflections library. EDIT: This is how I load the jar File: File f = new File("C:/Users/mkorsch

Run Gradle with verbose class loading?

梦想的初衷 提交于 2019-12-07 08:56:56
问题 My build script is encountering an error (below). Is there a way to run Gradle with the same type of output as invoking Java with -verbose:class ? The error in question, should anyone have some input: Caused by: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':Project:compile'. at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.wrapException(ErrorHandlingArtifactDependencyResolver.java:49) ... more Caused by

Why can't I instantiate a Groovy class from another Groovy class?

时光怂恿深爱的人放手 提交于 2019-12-07 08:20:43
问题 I have two classes. One.groovy: class One { One() {} def someMethod(String hey) { println(hey) } } And Two.groovy: class Two { def one Two() { Class groovy = ((GroovyClassLoader) this.class.classLoader).parseClass("One.groovy") one = groovy.newInstance() one.someMethod("Yo!") } } I instantiate Two with something like this: GroovyClassLoader gcl = new GroovyClassLoader(); Class cl = gcl.parseClass(new File("Two.groovy")); Object instance = cl.newInstance(); But now I get groovy.lang

Classloading Using Different Versions Of The Same Class : java.lang.LinkageError : attempted duplicate class definition for name

牧云@^-^@ 提交于 2019-12-07 07:10:09
问题 I have a working code that loads dynamically different Class Implementations with different Class Names. The class files are loaded into the in-memory database ( Apache Derby Db ), and classloader retrieve the .class file from the BLOB columns. What I want to do is, inserting the .class files as binary BLOB with version column and IS_ENABLED flags, then classloader will load the class for different versions on run-time. There will be db entries same amount of the compiled class versions and

AspectJ - Weaving with custom ClassLoader at runtime

纵然是瞬间 提交于 2019-12-07 05:28:36
问题 I'm trying to load classes at runtime and weave them with some AspectJ aspects at this point. I have load-time weaving enabled, and it works when I use it more conventionally. I have the following in my @Aspect class: @Before("call(* mypackage.MyInterface.*())") public void myInterfaceExecuteCall(JoinPoint thisJoinPoint, JoinPoint.StaticPart thisJoinPointStaticPart, JoinPoint.EnclosingStaticPart thisEnclosingJoinPointStaticPart) { System.out.println(thisJoinPoint.getSignature()

Java 9 - add jar dynamically at runtime

被刻印的时光 ゝ 提交于 2019-12-07 04:56:20
问题 I've got a classloader problem with Java 9. This code worked with previous Java versions: private static void addNewURL(URL u) throws IOException { final Class[] newParameters = new Class[]{URL.class}; URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class newClass = URLClassLoader.class; try { Method method = newClass.getDeclaredMethod("addNewURL", newParameters ); method.setAccessible(true); method.invoke(urlClassLoader, new Object[]{u}); } catch