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
0 answers

How to getResource from Bootstrap Class Loader?

In a Java application, the Bootstrap Class Loader (which is used to load classes from JRE such as rt.jar) is null. That is, java.util.ArrayList.class.getClassLoader() == null. This is annoying because when writing a library that uses reflection, one…
yonran
  • 18,156
  • 8
  • 72
  • 97
2
votes
2 answers

How to find out where a class originates from at runtime?

I'm having this weird issue where a class from some transitive dependency keeps showing up at runtime, shadowing a newer version of the class from the (correct) first level dependency, even though I thought I made sure that I excluded the older…
mxk
  • 43,056
  • 28
  • 105
  • 132
2
votes
1 answer

How to perform an action each time a class is loaded or a resource is found?

I have this class: public class UnusedJarDetector { public static void onDefineClass(Class clazz, ClassLoader classLoader) { ... } public static void onGetResource(URL url, ClassLoader classLoader) { ... } ... And…
basin
  • 3,949
  • 2
  • 27
  • 63
2
votes
1 answer

How to add deploy.jar to classpath?

I am facing the problem: I need to add ${java.home}/lib/deploy.jar JAR file to classpath in the runtime (dynamically from java). The solution with Thread#setContextClassLoader(ClassLoader) (mentioned here) does not work because of this bug (if…
dma_k
  • 10,431
  • 16
  • 76
  • 128
2
votes
1 answer

Obtaining a list of all Java classes used from all JVM's?

I want to have a list of all the classes that are loaded within multiple threads/JVM's at a certain moment in time. I know that when you run java with the -verbose parameter, you can write it to a file as something like this: java -verbose:class…
Rens Groenveld
  • 960
  • 11
  • 28
2
votes
0 answers

Drools 6 with custom class loader

I have a class I would like to use in a Drools 6.0.1 decision table that is not in the default class loader. I created a custom class loader that I would like to use in Drools but I can only find the KieBaseConfiguration class to set it. This does…
bbreck
  • 21
  • 1
2
votes
3 answers

getPackage() returning null when my JUnit test is run from Ant

I'm having problems running a JUnit test. It runs fine in Eclipse, but now I'm trying to run it from the command-line using Ant. The problem is that the following code is returning null: getClass().getPackage(). I'm running my JUnit test like so: …
Phil Harvey
  • 1,160
  • 4
  • 13
  • 19
2
votes
2 answers

Is there a way to turn on some sort of JVM logging so I can see whats happening during classloading etc

I'm trying to optimize the startup time/class loading time of my Java web app because its on the Google App Engine and startup time is important. Is there a way I can turn on some sort of class loading debug messages or someway to see where time is…
Kyle
  • 21,377
  • 37
  • 113
  • 200
2
votes
1 answer

URLClassLoader keeps throwing ClassNotFoundException. What am I doing wrong?

I'm working on a university java project that requires me to implement a simple plugin architecture. A main application in Project A would have to load plugins from a specified directory located in another project B. After having done some research…
2
votes
1 answer

Java - Load a class outside of classpath. What are the options

I got a Java product which is used by many clients. The product gets added as a jar into the client's (say for example XYZ company who wants to use his product for their needs) code base and works independently. Its a stand alone product and all the…
juniorbansal
  • 1,249
  • 8
  • 31
  • 51
2
votes
6 answers

CodeIgniter: "Cannot redeclare class"

Admittedly my OOPHP is a little shaky but I can't see what's wrong with this. In one of my controllers I'm including a utils sheet which, like the controller, extends the base CI_Controller class. This throws the fatal error: Fatal error: Cannot…
Mitya
  • 33,629
  • 9
  • 60
  • 107
2
votes
1 answer

How jvm classloader loads class that is defined inside another class?

How does JVM loads class that are defined inside another class? Example: Lets say, there is a class B that is defined inside class A package test.sample; Class A { // some instructions Class B { // few more…
Adhi
  • 149
  • 2
  • 11
2
votes
1 answer

Dynamically loading a Scala object

I have a number of objects (not classes) that manipulate databases, and I want to make a smaller helper class so I can do something like java my.helper.class my.database.class and execute the the run method. For example, this compiles trait A…
user2526527
2
votes
1 answer

Phalcon query model from controller in different module

I'm creating a multi module app. It's a big app that I am porting to Phalcon. It has many different sections, so I am creating a module for each of the main ones. I do not seem to be able to query a model in one module from a controller in another…
Ally
  • 955
  • 1
  • 15
  • 33
2
votes
1 answer

getResourceAsStream in a static block sometimes returns null

I have some code that does this at the top of a class: static { ... mapper.addMappingConfig(ModelRestMapper.class.getResourceAsStream("/com/mycompany/myapp/rest/dozer/mapping/mapping.xml")); ... } This code sometimes fails with this…
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356