classloader

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

僤鯓⒐⒋嵵緔 提交于 2019-12-05 17:05:38
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 there will only one class with IS_ENABLED flag set to TRUE . Because that I try to load the same class

Is it necessary to keep classes of the same package in the same dex while using multiple dex files

六月ゝ 毕业季﹏ 提交于 2019-12-05 16:46:53
About the Title "classes of the same package" means classes that share the same package access. Please pay attention to the fact that class a.b.c.Foo doesn't have package access to class a.b.Bar . Because the latter can't access to the former if the former's modifier is default. Problem If I split two classes in the same packages into two dex files, even though I load them correctly, I will also get some error while running, the logcat likes: I/dalvikvm( 6498): DexOpt: illegal method access (call Lcom/fish47/multidex/Foo;.isWholeWord (Lcom/fish47/multidex/Foo;)Z from Lcom/fish47/multidex

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

若如初见. 提交于 2019-12-05 16:45:28
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/Desktop/test-reflections.jar"); URLClassLoader urlCl = new URLClassLoader(new URL[] {f.toURI().toURL()}

What is the difference between getResourceAsStream with and without getClassLoader?

耗尽温柔 提交于 2019-12-05 16:40:02
问题 I'd like to know the difference between the following two: MyClass.class.getClassLoader().getResourceAsStream("path/to/my/properties"); and MyClass.class.getResourceAsStream("path/to/my/properties"); Thank you. 回答1: From the Javadoc for Class.getResourceAsStream(): This method delegates to this object's class loader. Before delegation, an absolute resource name is constructed from the given resource name using this algorithm: If the name begins with a '/' ('\u002f'), then the absolute name of

Tomcat classloader violates delegating policy

淺唱寂寞╮ 提交于 2019-12-05 15:45:02
Question1: As we know, when a classloader is about to load a class, it delegates the request to its parent classloader. However in Tomcat, it doesn’t: you could load your class to overwrite the same name class which is put in common lib directory. This means Tomcat WebappClassloader doesn’t follow delegating policy. Is it violation of convention? Question2: I wrote a class and put it in common lib directory, obviously the class is shared among web apps. For instance, every web app can read/write the static field of the class. Further, classes in JDK are loaded by Bootstrap classloader, then

remote jars in the classpath

情到浓时终转凉″ 提交于 2019-12-05 15:24:23
Sorry, maybe this question is too silly or already answered, but I couldn't find it out. I'm wondering if there is some known Java class-loader that is able to accept remote files in the classpath, i.e., entries like CLASSPATH="http://somewhere.net/library.jar:...". Note that I am not talking about applets or Java Web Start. Think of an application that can use different back-ends (e.g., MySQL, Oracle), I'd like to prepare the classpath in a shell script, based on the user's back-end preference and have the class-loader to download the needed jar (the jdbc driver in this example) from a

Apache Commons JCI ReloadingClassLoader

落花浮王杯 提交于 2019-12-05 11:01:53
Does anyone have any experience in using the ReloadingClassLoader of the Apache Commons JCI API? The only usage example can found in the following page: http://commons.apache.org/jci/usage.html I am assuming that whenever the directory or jar changes, it will automatically reload the classes within the classloader? If so, you would have to load/instantiate a previously loaded/instantiated class (by calling loadClass()) again to use the newly modified class? Is that correct? Hope this is clear. http://commons.apache.org/jci/apidocs/org/apache/commons/jci/ReloadingClassLoader.html - According to

AspectJ - Weaving with custom ClassLoader at runtime

拟墨画扇 提交于 2019-12-05 10:20:59
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().getDeclaringType()); System.out.println(thisJoinPoint.getSignature().getName()); } Then I'm scanning the jars and

How to load a resource from an embedded JAR File

梦想与她 提交于 2019-12-05 10:14:14
I am trying to load a resource that is contained within an embedded JAR file. The project is actually deployed in JBoss using an EAR file with the following structure: deploy.ear | |-> project.sar | |-> sub_project.jar | | | |-> settings.xml | |-> com/path/project/ | |-> main.class From main.java I'd like to get a InputStream for settings.xml . What is the correct way to do this? My current understanding that the following code should work, but it is returning null : this.getClass().getResourceAsStream("settings.xml"); Update After some trial and error, the following statements work: getClass(

Classloading order in JBoss

我是研究僧i 提交于 2019-12-05 10:13:00
I'd like to know if the default behavior of JBoss server (4.2.3.GA in my case) is loading the classes in parent-first or parent-last mode. And in case it work as I suspect in parent-last mode (i.e. first trying to load classes from the application's WEB-INF/lib and only if they are not found go to server\lib), how can I configure it to work in the opposite- first trying to load classes from outside and only looking inside the application afterwards. It sounds like you need to set java2ParentDelegation={false|true} in your jboss-app.xml or jboss-web.xml . See this article for more information.