classloader

convert Class object to bytes

If I have a Class instance at runtime, can I get its byte[] representation? The bytes I'm interested in would be in the Class file format, such that they'd be valid input to [ClassLoader.defineClass][3]. [3]: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassLoader.html#defineClass(java.lang.String, byte[], int, int) EDIT: I've ...

How do I use a more recent version of a hadoop/lib jar in my map/reduce jobs?

Hadoop currently ships with commons-httpclient-3.0.1.jar in its lib folder. If I have a map/reduce task that requires commons-httpclient-3.1.jar, it does not seem to be sufficient to bundle this jar in the lib folder of my hadoop jar (as one would do with any normal external jar dependencies), as hadoop seems to be loading the previous ...

Get bytes for a class that was generated at runtime

I am working with a Java framework that generates some (proxy) classes at runtime, using a custom ClassLoader. I would like to get for any such class that the custom ClassLoader returns from loadClass(..) the raw byte array that corresponds to this class. Is this possible? I know that if a class exists as a resource then you can use an i...

how to unload a already loaded class in java

how to unload a class from the class loader so that i can use the recently changed class on the fly without restarting my application(hot deployment). is it possible to do that. ...

What is iReport 3.7.0 doing with the Classloader?

I am facing very strange classloading issues with iReport 3.7.0. Here's some background context. We need to fill a Jasper report with data from a custom JRDataSource factory that uses POJOs to encapsulate the data. The POJOs are populated from data that resides in a database. In order for the client to "tweak" the report templates we...

How can I use different JARs for compiling and testing in maven?

I compile my programm against javaee-api. But for Junit testing I must use a specific implementation like glassfish's javaee.jar to avoid errors like java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence (see also 1). So avoid using methods, that are only a...

How can I make a URLClassLoader behave like this?

I'm trying to make a URLClassLoader which behaves as follows: If asked for a class whose name is in a given set of inclusions, load it as normal Otherwise, return a dummy class I can't get this to work. In the attempt below, I expect the SpecialClassLoader to load Test$Thing succesfully. In doing so, I expect it to attempt to l...

How can I write a ClassLoader that does this?

I'm trying to make a URLClassLoader which behaves as follows: If asked for a class whose name is in a given set of inclusions, load it as normal Otherwise, return a dummy class of my choice How should I go about this? My attempt at doing this didn't work - see my earlier question for details. ...

ClassLoader on virtual machine

I have source code: private Image getImage(String path, ClassLoader loader) { InputStream image = null; try { image = loader.getResourceAsStream(path); return new Image(PlatformUI.getWorkbench().getDisplay(), image); } finally { if (image != null) { try { image.close(); ...

Share interface classes using the same classloader on J2EE/Weblogic 10, without using the system classpath

Hi, I have a "framework" running on a Weblogic 10.0 (or 10.3) appserver, where the framework consists of multiple enterprise apps, each responsible for a different resource adapter. A client application gets deployed into the domain, uses JNDI to obtain reference to one of the resource adapter Connector classes, does its invocations and...

Need help understanding JNDI and a particular ClassCastException in J2EE

Hi! I have an enterprise application A and B deployed (in WLS 10.0). A is the "framework", B is a client app. The client issues the following calls: Object o = ctx.lookup(jndiName); // line 1 cf = (ConnectionFactory) o; // line 2 ConnectionFactory is an interface, defined as: public interface ConnectionFactory extends java.io.S...

compiling and running user code with JavaCompiler and ClassLoader

hi, I am writing web app for java learning. Using which users may compile their code on my serwer + run that code. Compiling is easy with JavaCompiler: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); CompilationTask...

if i know a class, how can i know which jar it is from?

for now i could use clazz.getClassLoader().getResource(class.getName()), then i substring the URL to get the jar file's location, but i really want to know if there is any better way to do it. is there any API for this? thank you. ...

How to find which jars and in what order are loaded by a classloader?

I could not find a clear answer to this question elsewhere, so I'll try here: Is there some way (programmatic or other) to get a list of JARs/classes loaded by an Application Classloader in the precise order they were loaded? By Application Classloader I mean the classloader that loads an EAR application in an applications server (WLS, ...

How to dynamically load class in Objective-C?

Hello, how to dynamically load a class in Objective-C? As per my need, class name will be in a text file, which i need to read it, and then load the class dynamically ... This code is loading a class in Java... I want the same functionality to be done in Objective-C... public class MainClass { public static void main(String[] args)...

Apache Commons JCI ReloadingClassLoader

Does anyone have any experience in using the ReloadingClassLoader of the Apache Commons JCI API? The only usage example can found in the following page: http://commons.apache.org/jci/usage.html I am assuming that whenever the directory or jar changes, it will automatically reload the classes within the classloader? If so, you would...

Are static initializers guaranteed to be called for AspectJ aspects?

This is my first question so please be gentle. :-) I know AspectJ can create pointcuts on static initializers of java classes. But the question is whether a static initializer in an aspect, as below, is guaranteed to be called exactly once: @Aspect public class MyAspect { private static Map configuration; static { // Some initia...

tomcat 5.5 web.xml change WEB-INF/lib directory

I have a jruby rails app that has some jar dependencies in rails lib/java. I prefer this to just putting them straight in lib as it separates my java libs from ruby libs. Works locally using jruby. Problem is, on deploy, tomcat is looking for a bunch of these jars (such as jruby) in WEB-INF/lib, not WEB-INF/lib/java. I think i need t...

problem with custom classloader

hi all. i want to implement a custom classloader in order to digitally signing my jar files. because of performance issues i don't want to encrypt all of my classes. so i want implement a custom classloader which when it has been called it delegates class to it's parent and if the parent failed to load class it handles by itself. this i...

How can I enumerate all child classes of a superclass in Java

My application consists of several JAR files. I would like to iterate over all of the JAR files and find all classes that subclass a particular class, so that I can cause their static initializers to run. I looked though the Javadocs for java.lang.ClassLoader, but can't find any method that does this. I am trying to implement the "Prod...