Questions tagged [classloader]

A class loader is an object that is responsible for loading classes in Java.

A class loader is an object that is responsible for loading classes in Java.

Given the binary name of a class, a class loader should attempt to locate or generate data that constitutes a definition for the class. A typical strategy is to transform the name into a file name and then read a "class file" of that name from a file system. A class loader may also chose to delegate to another class loader. It may do this before or after doing a normal lookup.

Every Class object contains a reference to the class loader that defined it. This class loader is used by the runtime for linking to other classes referenced by this class. Together with the name of the class the defining class loader uniquely identifies a class. It's therefore possible to have several classes in with the same name in Java as long as they have a different defining class loader.

4126 questions
2
votes
1 answer

How does Java find already loaded classes?

I know that Java uses the ClassLoader hierarchy for loading the classes. For example a program: public void test(){ A a = new A(); // Line 1 The class is accessed first time here so it should be loaded and defined A ab = new A(); //Line 2…
Narendra Pathai
  • 41,187
  • 18
  • 82
  • 120
2
votes
2 answers

Memory consumption of jars with many classes?

Scenario Let's assume an application with a dependency. The dependency comes in form of a jar file. The dependency jar file contains many classes. The application uses only one class from the dependency jar. Question Do the unused classes included…
user573215
  • 4,679
  • 5
  • 22
  • 25
2
votes
1 answer

Loading eclipselink domain model with custom classloader under weblogic

I have written a custom classloader to be able to dynamically load domain models for each step of an update process. In each step of the update a new thread is created to insure that not only the contextClassloader but the current classloader is…
pentike
  • 418
  • 4
  • 14
2
votes
2 answers

Load class within Jar file and get it's path

I know there are already a lot similar questions here, but I couldn't get any smarter form them. I want to load a class inside a jar file, at this point this is no problem, but when I want to pass the path to my own ClassLoader it throws an…
domizai
  • 343
  • 1
  • 5
  • 13
2
votes
1 answer

ClassLoader loading android class which extends android class from android support library

I am creating an extendable android application and I need to be able to load class which extends Fragment from different application (apk). String packageName = "com.something.project"; String className =…
BJMg
  • 61
  • 2
  • 5
2
votes
1 answer

Does a threadlocal variable need to be static to pose a memory leak

At this link here They describe memory leaks when using classloaders. Now this comment: A classloader will be removed by the garbage collector only if nothing else refers to it. All classes hold a reference to their classloader and all objects hold…
Victor
  • 16,609
  • 71
  • 229
  • 409
2
votes
1 answer

Doctrine classloader overwrites my __autoload function

I may generally misunderstand something about setting up a custom classloader. What happens is that once i initialize it: use Doctrine\Common\ClassLoader; require_once(DOCTRINE_PATH . '/Common/ClassLoader.php'); classLoader=new…
SquareCat
  • 5,699
  • 9
  • 41
  • 75
2
votes
2 answers

Checking if loaded class is assignable from another?

So, I have a custom classloader to load classes into memory from byte arrays, and I have a problem: When I attempt to see if a class is assignable from another(ClassLoader.isAssignableFrom), it returns false, even if the compiled class extends or…
user2507230
  • 562
  • 1
  • 3
  • 12
2
votes
1 answer

Custom hamcrest matcher in unit tests

Having trouble implementing custom hamcrest matcher to use in Grails. Running the tests using my matcher fails with: java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V After a bit of…
raaputin
  • 105
  • 4
2
votes
2 answers

Communication between different Jar's/Classloaders

I've got the following problem to solve: There are two jar files. These jar's start independently from each other. Now, let's say the first jar A.jar calculates or computes something and has to commit the results to B.jar. I tried to communicate…
smsnheck
  • 1,563
  • 3
  • 21
  • 33
2
votes
3 answers

ClassCastException by cast to owe type

In an implementation of org.dozer.BeanFactory.createBean(Object, Class, String) I try to cast the object to type of it. If I deploy all my bundles, that is to shut down and start all bundles I got a ClassCastException:…
2
votes
2 answers

java security classloader

I am implementing a service which uses a URLClassloader to load classes dynamically. In the interest of security I would like to restrict the access of loaded classes. eg no network, file or db access etc. Anybody got any good resources or…
Hoax
  • 1,004
  • 2
  • 15
  • 31
2
votes
2 answers

Does Custom ClassLoader lead to memory leaks?

ClassLoaders are stored in Permanent generation memory . And as specified in white paper of java Memory Management in the Java HotSpot™ Virtual Machine, permanent generation memory is garbage collected for sure. So, Does custom Classloader still…
Mac
  • 1,711
  • 3
  • 12
  • 26
2
votes
1 answer

Java7 bootstrap: Checking class without loading?

When reading the answer to this question, I was wondering how Java7 bootstrap knows about the presence of public static void main(String[] args) method, without running the static initializers? I have some assumptions on this topic, but some of them…
gaborsch
  • 15,408
  • 6
  • 37
  • 48
2
votes
2 answers

How to resolve class name to fully qualified in Java?

Is there any way in Java to resolve simple class name (e.g. String) to fully qualified one (e.g. java.lang.String) or better yet to Class directly? The only way that comes to my mind is to parse file for imports and figure out from classpath jars.…
Albert Latacz
  • 33
  • 1
  • 6
1 2 3
99
100