classloader

Unit testing both the presence/absence of a library

The question: Is there a way I can use a ClassLoader to test both the presence and absence of the library I'm checking for? I have a some code which will use a particular library if available, or fall back to some embedded code if not. It works fine but I'm not sure how to unit test both cases in the same run, or if it's even possible. ...

Can I write a Java loader class that will hook HTTP requests in the loaded class?

I have a class that I want to hook and redirect HTTP requests in. I also have a loader class already written, but all it does it replace the functions that contain the HTTP requests I want to change. Is there a way to hook HTTP requests in Java so that I can redirect them all more easily? Sort of like a proxy-wrapper. Clarification: The...

JBoss, sync4j and class loading

Hello there, I'm in need of some help with running one webapp (sync4j) with jboss 6 I'm getting the following error: could you help me with this? I found here: https://community.jboss.org/wiki/ClassLoadingConfiguration that i need to add this: <jboss-app> ...

Any good resource on JBoss5.1 class loading

I'm debugging a thorny CL-related problem and need a better understanding of how classloading works in JBoss 5.1. Yes, I read http://community.jboss.org/wiki/JBossClassLoaderIntroduction and http://community.jboss.org/wiki/JBossClassLoaderOverviewandGoals; they are useful to start with, but are not very precise in their description. The...

Java security: Sandboxing plugins loaded via URLClassLoader

Question summary: How do I modify the code below so that untrusted, dynamically-loaded code runs in a security sandbox while the rest of the application remains unrestricted? Why doesn't URLClassLoader just handle it like it says it does? EDIT: Updated to respond to Ani B. EDIT 2: Added updated PluginSecurityManager. My application ha...

dynamically load implementation of interface in Java

I'm looking for functionality in Java similar to the .NET Managed Extensibility Framework (http://mef.codeplex.com/). For those who don't know MEF, I want something like this: Given an interface public interface IFoo { ... } Dynamically load an implementation of an interface by looking in loaded jars. IFoo foo = loadClassThatI...

Getting a resource in a different project using classloader.

Using the ClassLoader#getResource(), I need to access a file that is present in a project other than the one where my current code resides. How can this be done? I'm using eclipse. Directory Structure: Root |-project1 | |-package | |-myResourceFile |-project2 |-package |-myCodeFile I'm trying to get myResource...

How to modify JBoss classload to use different versions of third party library jars (parent last)

I'm trying to figure out how to set up JBoss 5.1.0 so that the classloader is parent last, which I have done before with WebSphere. Basically we have several war files that need to use Spring 3. We have put the spring jars in the JBoss lib, so that we don't have to have spring jars inside each and every war file. However, one of the web ...

Can a loaded JAR be deleted by the Java-Process?

Hello I have following Problem: Within an uninstall-process I load a JAR (jdbc-driver). URL pDriverJar = jarToDelete.toURI().toURL(); URL[] lURLList = new URL[]{pDriverJar}; URLClassLoader lLoader = new URLClassLoader(lURLList, Thread.currentThread().getContextClassLoader()); Thread.currentThread().setContextClassLoad...

How to compare 2 classes which are loaded from 2 different classloader.

here is my case: classloader A, loaded one class("Class1"); then, I changed Class1.java and compile it. next I loaded Class1.class again by classloader B. I want to compare these 2 classes, check whether the class meta data changed by someone. Is there any way to compare 2 classes' definition data? ...

Dynamically load a class in JAVA- Anomaly

Guys, I have got a slightly different problem with Java Dynamic class loading. I have to pass an object( lets say Object A1 of class A) to the constructor of a different object B1 of class B, So that the A1's details are stored inside B1. B1 does not know what kind of object it is receiving. So all it knows is that A1 is an object. N...

Accessing Methods and functions of a object whose class type is dynamically known

Guys, I have an object A1 of type A. I dynamically find that out , that object A1 is of type A. I now have a property say "Name" which I want to access from A1 , how do I do it ? Now the biggest problem is that the object A1 can even be of type B. If it is of type B then I will have to obtain the value "Address". Now How I resolve thi...

Different classloaders cause ClassCastException when persisting data via Spring

I'm creating an MVC Spring webapp. Using: Jetty (servlet container), DataNucleus (dao platform), DB4O (embedded datastore). When I persist an object (done from within a Spring Controller) using JDO from DataNucleus, it stores to the DB fine. @PersistenceCapable public class Test { @Persistent private String testString; //g...

ClassCastException in DataNucleus DAO object when persisting/retreiving an Object using JDO

I've created a simple webapp using Spring & Jetty, and am creating a hello world JDO test using DataNucleus & DB4O. I can persist a class no problem, but when I go to query for the class I get a ClassCastException, can't cast a.b.c.MyClass to a.b.c.MyClass. When I examine the classloader of the original object I created, it's [WebAppCl...

How can I run my code upon class load?

Is there a feasible way to get my own code run whenever any class is loaded in Java, without forcing the user explicitly and manually loading all classes with a custom classloader? Without going too much into the details, whenever a class implementing a certain interface read its annotation that links it with another class, and give the...

JBoss Classloader Repository

Hi all, Running JBoss 4.2.3.GA and trying to deploy a WAR that is using Spring/Hibernate/JPA. I'm getting ClassCastExceptions (quite a lot of different ones) so I'm trying to setup a Classloader Repository for my WAR. This is my catalog.war/WEB-INF/jboss-web.xml file <jboss-web> <loader-repository> com.moo.catalog:loader=...

PHP custom class loader

i made a custom class loader function in php something like.. load_class($className,$parameters,$instantiate); its supposed to include the class and optionally instantiate the class specified the problem is about the parameters. ive been trying to pass the parameters all day i tried load_class('className',"'param1','param2'",TRUE); ...

How to find all implementations of a certain interface?

I want to make my program initialization a bit "smarter". I have several classes which represent commands. All these classes are immutable (i.e. creating only one instance of each should be enough for the whole application). All these classes implement Command interface. I think that the fact that some classes are placed in the same ...

Overriding default accessor method across different classloaders breaks polymorphism

Hello. I come across to a strange behavior while trying to override a method with default accessor (ex: void run()). According to Java spec, a class can use or override default members of base class if classes belongs to the same package. Everything works correctly while all classes loaded from the same classloader. But if I try to load...

Runtime code generation and compilation

Say I have this code that uses some input (e.g. a URL path) to determine which method to run, via reflection: // init map.put("/users/*", "viewUser"); map.put("/users", "userIndex"); // later String methodName = map.get(path); Method m = Handler.class.getMethod(methodName, ...); m.invoke(handler, ...); This uses reflection so the per...