classloader

Difference between AppClassloader and SystemClassloader

血红的双手。 提交于 2019-12-02 20:59:07
I am so confused about these two class loaders. When talking about the hierarchy of Java class loaders, usually the bootstrap classloader and ext class loader and the third one (system classloader or app classloader) are mentioned. To be more accurate, I checked the source code of JDK. In class Launcher , there is the code: loader = AppClassLoader.getAppClassLoader(extcl); In class ClassLoader , the method: getSystemClassloader() Also says the system classloader is used to start the application. So which is the third one in the hierarchy, or are the two classloaders the same? Ravindra babu

What do people use class loading for?

∥☆過路亽.° 提交于 2019-12-02 20:43:20
So, every Java text book talks about how flexible Java is since it can load classes at run time. Just cobble together a string and give it to Class.forName() , and catch the ClassNotFoundException and handle it. So much for the theory. Can you give examples of how you've been using Java class loading to achieve a feature which otherwise wouldn't have been possible or easy? Note that I'm not asking "what great things could we do?" - I'm looking for real-world examples, be it an open-source application or - if you can describe this without giving out too much details - a proprietary application.

Is the Java classpath final after JVM startup?

好久不见. 提交于 2019-12-02 20:29:07
I have read a lot about the Java class loading process lately. Often I came across texts that claimed that it is not possible to add classes to the classpath during runtime and load them without class loader hackery (URLClassLoaders etc.) As far as I know classes are loaded dynamically. That means their bytecode representation is only loaded and transformed to a java.lang.Class object when needed. So shouldn't it be possible to add a JAR or *.class file to the classpath after the JVM started and load those classes, provided they haven't been loaded yet? (To be clear: In this case the classpath

What does the sun.reflect.CallerSensitive annotation mean?

烈酒焚心 提交于 2019-12-02 20:12:20
What is implied by @CallerSensitive annotation above methods? For example,the annotation is present in getClassLoader method of Class @CallerSensitive public ClassLoader getClassLoader() { // } According to the JEP I linked to in the comments (also here ), A caller-sensitive method varies its behavior according to the class of its immediate caller. It discovers its caller’s class by invoking the sun.reflect.Reflection.getCallerClass method. If you look at the implementation of Class#forName(String) @CallerSensitive public static Class<?> forName(String className) throws ClassNotFoundException

Java ClassLoader delegation model?

心不动则不痛 提交于 2019-12-02 19:31:39
When calling loadClass() on a ClassLoader , does the ClassLoader first check if the class has been loaded, or does it immediately delegate this check to its parent ClassLoader ? Java API says: When requested to find a class or resource, a ClassLoader instance will delegate the search for the class or resource to its parent class loader before attempting to find the class or resource itself. But there's a specific chapter about class loader in the book Java Reflection in Action that says: Class loader calls findLoadedClass to check if the class has been loaded already. If a class loader does

How does clojure class reloading work?

白昼怎懂夜的黑 提交于 2019-12-02 15:37:39
I've been reading code and documentation to try to understand how class reloading works in clojure. According to many websites, such as http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html , whenever you load a class essentially you obtain the bytecode (via any data mechanism), convert the bytecode into an instance of class Class (via defineClass), and then resolve (link) the class via resolveClass. (Does defineClass implicitly call resolveClass?). Any given classloader is only allowed to link a class once. If it attempts to link an existing class, it does nothing.

loading class at runtime in java ClassNotFoundException

人盡茶涼 提交于 2019-12-02 14:22:59
问题 I am having problems calling classes at run time in java Im basically making a plugin framework it starts off by opening plugin/Plugins.cfg and parses the test into a map.. EX text in cfg file 1 = myplugin 2 = plugin2 (each plugins main class is: plugin.(plugin name).main.class) as you can see it loads each value from the map and trys to run its main class public static void loadPlugins() { int x = hackers.core.startup.InitializeGame.map.size(); for (int i = 1; i<=x;i++) { String className =

Android's basic components' class loading & _java objects_ lifecycle

落爺英雄遲暮 提交于 2019-12-02 13:09:55
问题 While there are countless resources on Application, Activity etc lifecycle seen from an API perspective ( onCreate/Destroy/Whatnot() methods) there is scarcely any information on the actual object's lifecycle for these components from the Java perspective . So for instance I saw (on a YouTube marakana video) that services are basically singletons - and this left me wondering on the state of an IntentService - can it be shared ? Or is this a singleton too ? I guess initially a process is

Load all classes in a specific folder without knowing package name - java

六眼飞鱼酱① 提交于 2019-12-02 10:46:54
I have a code that load all classes in folder with same package name ( second ). how can i change it to load all classes in a folder with deference package (not in second ) (and we don't know the package name) int classCounter = 0; File folderAdded = new File("..//940424//second"); File [] classFileAdded = folderAdded.listFiles(); String [] addedClassName = new String [classFileAdded.length]; List<Operations> newOp = new ArrayList<Operations>(); Operations newOpTemp = null; for(int i = 0; classCounter < classFileAdded.length; classCounter++){ addedClassName [classCounter] = classFileAdded

cannot find symbol, java, classloader

。_饼干妹妹 提交于 2019-12-02 10:32:17
Currently doing a typestate project and I am having problems with importing the List class. When I try to compile the class it throws an error in command line saying cannot find symbol and points to the List symbol. I was wondering how you fix this. It seems to work for String and Integer but not for List. The java file is automatically create via another program that translates .scr files. In the scr file I use the following line : type <java> "java.lang.List" from "rt.jar" as List; Java file: package demos.Redis; import java.io.BufferedReader; import java.io.IOException; import java.io