Questions tagged [dynamic-class-loaders]

The Java Classloader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine.

Dynamic Class Loading allows the loading of java code that is not known about before a program starts. Many classes rely on other classes and resources such as icons which make loading a single class unfeasible. For this reason the ClassLoader (java.lang.ClassLoader) is used to manage all the inner dependencies of a collection of classes. The Java model loads classes as needed and need not know the name of all classes in a collection before any one of its classes can be loaded and run.

188 questions
6
votes
6 answers

Java: Strong Code mobility How to?

Does anyone know how to use Java for Strong code mobility? Have you ever done it before? Here's what I try to achieve. Suppose we have 2 separate Java applications that communicate over network. App A and App B. App A has a class x instantiated as…
sivabudh
  • 31,807
  • 63
  • 162
  • 228
6
votes
3 answers

How do I control which ClassLoader loads a class?

The situation at hand is not as simple as the title seems to indicate. Java 1.6_17 running via JWS. I have a class, lets say MyClass and one of its instance member variables is a Type from an errant 3rd party library where during class…
5
votes
2 answers

When is finalize called on singletons when a classloader is released?

By "released" I mean there are no references to the classloader remaining. We're running into a problem where a frequently-redeployed Java EE application eats up permgen space. Analysis shows that a singleton in the Java EE app has passed…
Ed Staub
  • 15,480
  • 3
  • 61
  • 91
5
votes
2 answers

Load classes from folder without specifying the package

I have an application that allows, using an abstract class, people to write their own implementations. I load these implementations as .class-files from a directory. Currently, I have this solution: File classDir = new…
F.P
  • 17,421
  • 34
  • 123
  • 189
5
votes
1 answer

Java: Where does the Extensions Class Loader get classes from in Java 13?

All the documentation I've been able to find mentions the 'jre/lib/ext' folder but such does not exist on my JRE 13 installation. I guess somewhere between Java 8 (where I can see the jars in jre/lib/ext) and Java 13, they moved but I've been…
DraxDomax
  • 1,008
  • 1
  • 9
  • 28
5
votes
1 answer

java 8 reflection doesn't work

We use the hibernate validator and dynamically class-loading in our project (by load class into a separate class-loader). After we realise that the class is not required we remove all references to the class and class-loader, then GC collects…
5
votes
0 answers

Mockito's mock throw ClassNotFoundException in Spark application

I found that mock object in Mockito would throw ClassNotFoundException when used in Spark. Here is a minimal example: import org.apache.spark.{SparkConf, SparkContext} import org.mockito.{Matchers, Mockito} import org.scalatest.FlatSpec import…
K.Chen
  • 1,166
  • 1
  • 11
  • 18
4
votes
4 answers

Java custom class loader issue

I'm sending a Class object from client to server side. Every time the server needs to load the Class object sent by the client instead of reusing it by parent delegation model (when it was loaded during the 1st iteration). I'm trying to use a custom…
RRM
  • 2,495
  • 29
  • 46
4
votes
2 answers

Unexpected behaviour in JVM class loading (ClassNotFoundException before the class is really needed)

I would need help trying to understand why this is happening to me: Using Java 1.8.0_131, I have a class such as this: public class DynamicClassLoadingAppKO { /* * THIS VERSION DOES NOT WORK, A ClassNotFoundException IS THROWN BEFORE EVEN…
Daniel Fernández
  • 7,335
  • 2
  • 30
  • 33
4
votes
2 answers

Using URLClassLoader to load .class file

I'm aware that this question has been asked before: How to use URLClassLoader to load a *.class file? However I don't really understand due to the lack of example. I'm currently working on a project and trying to load user-given .class objects which…
Last
  • 59
  • 1
  • 6
4
votes
1 answer

Java reflection, how to reload a changed and recompiled class at runtime?

I am working on an IDE like project where code changed by user gets recompiled by JavaCompiler at runtime and needs to be reloaded to execute the changed code, I am using reflection to do that, but the problem is the class once loaded by ClassLoader…
user1306589
4
votes
2 answers

How to load a Class using only the class name

I need to use Java's Class.forName("") to load one of my classes. Problem is that I need to load the class by only specifying the class name and NOT the fully qualified class name. For example this works but doesn't fit my…
Marquinio
  • 4,601
  • 13
  • 45
  • 68
3
votes
1 answer

Beanshell will not allow me to add jars to the "default" JRE classloader?

I have a question about Beanshell that I can't find an answer to anywhere. I am only able to run Beanshell scripts in 1 of 2 ways: Where Classpath is defined before invoking Beanshell and Beanshell uses the JRE default classloader. Where no…
djangofan
  • 28,471
  • 61
  • 196
  • 289
3
votes
1 answer

boolean initialize parameter of class.forName method in java

Although I read the documentation, I'm not able to understand what is the difference here between those two lines of java codee when loading a class: Class cls = Class.forName("jdk.nashorn.api.scripting.ScriptObjectMirror", false,…
Ahmet Eroğlu
  • 594
  • 1
  • 7
  • 23
3
votes
2 answers

Loading a external jars dynamically in a spring boot application @runtime

We have a spring boot application which is referring to a 3rd party jar . The 3rd party jar is having all getters and setters . But this external JAR keeps changing periodically . This external jar is places in shared location . Is there a way by…
Sat
  • 33
  • 1
  • 3
1
2
3
12 13