classloader

How is the Java Bootstrap Classloader loaded? [duplicate]

别说谁变了你拦得住时间么 提交于 2019-11-28 20:57:42
问题 This question already has answers here : What loads the java system classloader? (4 answers) Closed 2 years ago . In java, it is said that all the classes are being loaded by classloaders. So first of all, bootstrap classloader loads all the rt.jar classes. So I am still confused as Classloader is also a class, so who will load this BootStrapClassloader. Kindly explain. 回答1: Answer : When a JVM starts up, a special chunk of machine code runs that loads the system classloader. This machine

Creating a ClassLoader to load a JAR file from a byte array

笑着哭i 提交于 2019-11-28 20:52:35
I'm looking to write a custom class loader that will load a JAR file from across a custom network. In the end, all I have to work with is a byte array of the JAR file. I cannot dump the byte array onto the file system and use a URLClassLoader . My first plan was to create a JarFile object from a stream or byte array, but it only supports a File object. I've already written up something that uses a JarInputStream : public class RemoteClassLoader extends ClassLoader { private final byte[] jarBytes; public RemoteClassLoader(byte[] jarBytes) { this.jarBytes = jarBytes; } @Override public Class<?>

How to safely access the URLs of all resource files in the classpath in Java 9/10?

空扰寡人 提交于 2019-11-28 20:51:04
问题 We learned from the release notes of Java 9 that The application class loader is no longer an instance of java.net.URLClassLoader (an implementation detail that was never specified in previous releases). Code that assumes that ClassLoader::getSytemClassLoader returns a URLClassLoader object will need to be updated. This breaks old code, which scans the classpath as follows: Java <= 8 URL[] ressources = ((URLClassLoader) classLoader).getURLs(); which runs into a java.lang.ClassCastException:

Java class loader tutorial [closed]

故事扮演 提交于 2019-11-28 19:17:44
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Please provide a good, thorough tutorial about Java class loading , focusing on how to extend that mechanism and how to actually work with the extension. 回答1: There's obviously Sun's trail which gives you the technical foundations. I find that despite being thirteen years old(!) this JavaWorld article is still a

Jar hell: how to use a classloader to replace one jar library version with another at runtime

风流意气都作罢 提交于 2019-11-28 19:10:33
I'm still relatively new to Java, so please bear with me. My issue is that my Java application depends on two libraries. Let's call them Library 1 and Library 2. Both of these libraries share a mutual dependency on Library 3. However: Library 1 requires exactly version 1 of Library 3. Library 2 requires exactly version 2 of Library 3. This is exactly the definition of JAR hell (or at least one its variations). As stated in the link, I can't load both versions of the third library in the same classloader. Thus, I've been trying to figure out if I could create a new classloader within the

Are static fields in Activity classes guaranteed to outlive a create/destroy cycle?

一世执手 提交于 2019-11-28 17:18:43
I frequently run into the problem that I have to preserve state between several invocations of an activity (i.e. going through several onCreate()/onDelete() cycles). Unfortunately, Android's support for doing that is really poor. As an easy way to preserve state, I thought that since the class is only loaded once by the class loader, that it would be safe to store temporary data that's shared between several instances of an activity in a static Bundle field. However, occasionally, when instance A creates the static bundle and stores data in it, then gets destroyed, and instance B tries to read

What are the differences between the various Java plugins for hot class reloading and which one is the most intuitive?

↘锁芯ラ 提交于 2019-11-28 17:16:15
I am currently trying to implement hot class reloading in a Java application, however there are so many plugins to choose from and I cannot find a good comparison between the options. Also the websites of the plugins are not all very clear on what the exact features are and how to use them. There is also the option of making a custom hot class reloading ClassLoader , but I feel like that is similar to "reinventing the wheel" if there are already so many plugins which can do the job.. do other people agree with this? The Java plugins I found which I think can do the job: JRebel Dynamic Code

How to find which jars and in what order are loaded by a classloader?

99封情书 提交于 2019-11-28 16:39:54
I could not find a clear answer to this question elsewhere, so I'll try here: Is there some way (programmatic or other) to get a list of JARs/classes loaded by an Application Classloader in the precise order they were loaded? By Application Classloader I mean the classloader that loads an EAR application in an applications server (WLS, WAS, JBoss...), but obviously, it applies to any classloader. So, to generalize, what I would like to find out is the list and order of JARs loaded by a specified classloader. Not individual classes, that is easy enough to find out by calling the classloader

Java Class Loaders [closed]

♀尐吖头ヾ 提交于 2019-11-28 15:55:08
Can anyone point me a good resource or explain me about the concept behind Class Loaders? I found the following resource on class loaders http://www.onjava.com/lpt/a/5586 but still no help. The following questions may look silly but trying to answer them always confuses me. Why do developers write Custom class loaders, why not invoke a Bootstrap class loader to invoke your custom classes? What is the need to define custom class loaders? Why there are so many varieties of class loaders? eg: Bootsrap, Comman, Catalina class loader etc., Thanks in advance. I found the following, valid reasons to

What can done to secure jar files besides obfuscation?

隐身守侯 提交于 2019-11-28 13:42:58
I'm concerned about the security of Java executables. They offer little protection against decompilation. With tools like Java Decompiler even a kid can decompile the class files to get the original code. Apart from code obfuscation what can be done to protect a class file? Is the Encrypted Class Loader still a myth? Riduidel In a previous company we had such questions, mainly driven by management paranoia. First of all, you have to understand that absolute security is only a myth: As long as your program is run on untrusted hardware, it can be decompiled, no matter what language you use. The