classloader

Copy java object/class from one classloader to another classloader

Hi is there a way to copy one class loaded context (atrributes etc) from one classloader (for instance a 'made' class Point) to another classloader? Making clear, Example: I have an object Point on CL 1. Now running on another CL2, I want to creat this object in CL 3. Some obj: class Point { int x; int y; public Point() {} //getters...

osgi-like framework without the import/export restrictions?

I like OSGi, but the import/export restrictions and the lack of context class loader creates havoc when trying to use 3rd party libraries (e.g., some libraries try to find file.xml in META-INF, expecting for all such files in all jars to be returned, other libraries use ServiceLoader). I want OSGi's dynamic loading, ability for handling...

How to use implementation loaded with different Java classloader?

I am writing a library where I allow people to provide implementations of certain interfaces using a plugin framework (it's JPF if you're familiar). The plugins are not stored in the classpath. The framework gives me a ClassLoader for each plugin, so when implementation named "MyImpl" of interface "MyInterface" is requested, I can find...

java: Difference between thread's context class loader and normal classloader

What is the difference between a thread's context class loader and a normal classloader. That is, if Thread.currentThread().getContextClassLoader() and getClass().getClassLoader() return different class loader objects, which one will be used? ...

Java: How to load Class stored as byte[] into the JVM?

If one has serialized the entire .class file into byte[], and assuming the name of the class is known (passed along with the byte[]), how do you convert byte[] -> Class -> then load it to the JVM so that I could later use it by calling the Class.forName()? NOTE: I'm doing this because I sent the .class over to another host, and the host...

java dynamic classloader

hi how can I dynamically load a class in Java with two parameters which are the absolute filepath of the class file and the name of the method I wish to call? eg path: c:\foo.class method: print() I am just interested in the basics as a simple cmd line tool. A code example would b appreciated. cheers hoax ...

java security classloader

hi 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 tutorials on the web for this kind of thing? cheers hoax ...

loading BufferedImage with ClassLoader.getResource()

Hello, I am trying to load an image file (gif) which is stored locally in the same directory as my Eclipse java project: ref is the relative path where the gif image is stored. public Sprite getSprite(String ref) { BufferedImage sourceImage = null; try { URL url = this.getClass().getClassLoader().getResource(ref); ...

Is there a way to force a classloader to load a package even if none of its classes have been loaded?

Let's say a java codebase has a package called "com.example". At runtime, we can get this Package by calling Package p = Package.getPackage( "com.example" ); //(returns null) or even get a list of all packages by calling Packages[] ps = Package.getPackages(); The problem is - if the ClassLoader has not yet loaded any class from th...

Groovy classloader bug?

I've encountered buggy behavior: import groovy.xml.DOMBuilder def filePath = "MestaXml.log"; def doc = DOMBuilder.parse(new FileReader(filePath)); def docElm = doc.documentElement; - $ groovy SaveTransformer.groovy Caught: java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated lo...

How can I safely solve this Java context classloader problem?

One and only one of my hundreds of users has trouble starting my Java desktop app. It only starts for him about one-third of the time. The other two-thirds of the time a NullPointerException is thrown at startup: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at java.util.Hashtable.put(Hashtable.java:394) ...

Is it possible to have the System ClassLoader load .class files specified at run time?

I am writing a static analysis tool for an assignment, it analyses Java bytecode using the ASM library. One of the parts of ASM that we use requires (or at least, appears to require) that the class be loaded from the ClassLoader. We were hoping the tool would be able to analyse .class files without requiring them on the classpath. We al...

Load resource from JAR without accessing ClassLoader?

Is there a simple way to load resource from my own executing JAR as InputStream without accessing ClassLoader? The problem is that my java.policy restricts accessing ClassLoader (this cannot be changed). I want to load some xml config which I can put anywhere in my JAR, but cannot have it outside the JAR. Thank you for answers. Actually...

Websphere Classloading

We have an application deployed in Websphere application server 7. Its deployed and functioning in various environments. But it gave a method not found exception in one new env. On digging deeper we found that a particular class was present in 2 jars and the class from the "wrong" jar was getting loaded in the new env. i went through the...

getClass().getClassLoader() is null, why?

Hi, I've got some code that calls.. x = getClass().getClassLoader(); This returns null though. When I start the same code not from Eclipse, but the command line, it returns a classloader. I can hack the code to do this... if (getClass().getClassLoader() == null) { x = ClassLoader.getSystemClassLoader().getSystemResourceAsStream( ...

Failing to load font after burning to disk

I have an application which has a font stored within a jar file. It is loaded with: public Font getChessFont() { InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("fonts\\MERIFONTNEW.TTF"); Font toReturn; try { toReturn = Font.createFont(Font.TRUETYPE_FONT, in); } catch (Exception e) { toReturn = gam...

addEventListener to loader? or loaded swf?

I am loading an external swf file using the following code: //add close button var reqButton:URLRequest = new URLRequest(btn_close); var loader2:Loader = new Loader(); loader2.load(reqButton); addChild(loader2); loader2.addEventListener(MouseEvent.CLICK, closeInfoBubble); function closeInfoBubble(event:MouseEvent):void ...

log4j and the thread context classloader

I'm a newbie to Java and just starting to figure out the concept of class loaders. Right now I am having some issues with log4j regarding its use of the thread context classloader. I'm getting the following errors: A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable. The class "org.apa...

Determine which jar file a class is from

Hi all, I am not in front of an IDE right now, just looking at the API specs ... CodeSource src = MyClass.class.getProtectionDomain().getCodeSource(); if (src != null) { URL jar = src.getLocation(); I want to determine which jar file a class is from, is this the way to do it? Walter ...

Help using ClassLoaders

Hi everyone! I'm trying to get this thing with using different ClassLoaders to work with no success and I'm getting kind of desperate. What I'm trying to do is to launch 2 different instances of a 3rd party program that was created with several static attributes and therefore can't just be instantiated twice in my code. I've been advise...