classloader

Reading files inside a JAR file

Hi, I am trying to read database scripts in a Jar file so that I can split up my import.sql files as many times as I see fit. For instance, I have several projects or modules that provide reference data, so I have a few separate scripts in each project that declares that. Instead of having one large import.sql, my approach was to spli...

How to determine what classes have been loaded from where in JBoss

I seem to remember some function in the JMX console which allows you to type in a class name, and see the classloaders which loaded it, and from which resources the class was loaded from. Unfortunately, I can't seem to find this. For standalone apps, I've always used the JWhich tool to get this information. ...

Is there a way to get which classes a ClassLoader has loaded?

I am trying to implement some unit testing for an old framework. I am attempting to mock out the database layer. Unfortunately our framework is a bit old and not quite using best practices so there is no clear separation of concerns. I am bit worried that trying to mock out the database layer might make the JVM load a huge number of clas...

Dynamically loading a Jar file will not work; have tried a lot

Hi, my app basically stores a jar file in a "Blob" in mysql and then grabs it through a PHP file. This is not a problem, because doing: $ wget http://path/to/php $ jar tf file.jar shows the classes perfectly fine. I have tried many things, and the farthest I've gotten is when using ClassLoader.loadClass() when I call newInstance() it...

Singleton across classloaders/EJB:How to avoid multiple instance of JCS Cache due to multiple class loader/EJB's?

I want to use JCS (Java Cache System) to cache ldap queries which should be shared by multiple EJB's (class loaders) to avoid the duplicate searches. I have created a singleton wrapper to create only one instance of JCS cache but due to each EJB's having their own class loader, it creates multiple instance of JCS cache so ldap search re...

ClassLoader loading wrong file

I use this code snippet to obtain a file as an input stream. The file version.txt is packaged in my app's jar, in the upper-most folder. InputStream resource = getClass().getClassLoader().getResourceAsStream("version.txt"); This works almost all of the time. But for one user, it's picking up another version.txt, that's not in my jar. ...

How do you share Java Caching System (JCS) resource across multiple EJB

I am using JCS to store the ldap search results which should be shared by multiple EJB. I have created a singleton class to initialize JCS only once but due to EJB's classloader, it's been initialized multiple times with its own copy. so search resources are not shared. How are you guys resolving issue where you need to share the cache ...

How to get classloader for a bundle in equinox?

How can I get the classloader for a osgi bundle in eclipse equinox setup. Thanks, Suraj ...

Java Classloader - how to reference different versions of a jar

Hi All, This is a common problem. I'm using 2 libraries A.jar and B.jar and these depend on different versions of the same jar. Let's say that at runtime I need THIS.x.x.x.jar MY.jar -> A.jar -> THIS.1.0.0.jar -> B.jar -> C.jar -> THIS.5.0.0.jar I can compile the specific jar (A.jar/B.jar) against its dependency but at r...

Who needs to see who in a JPA application?

I have code using JPA and everything works fine in my development environment and in unit tests. But deploying my modules into the OSGi target environment, I regularly run into the weirdest class loading issues. I really like OSGi, but if I can't fix this once and for all, I'm going to get stark raving mad. And as long as I don't underst...

Dynamic loading problem when program executes from a jar

Hi all, I have an application which is extendable through java classes that conform to a given interface. If I run the program from the command line classes, I am able to instantiate the add-on classes using: Class.forName("myAddon").newInstance(); However if I jar the application (setting the main class correctly), I get a class not...

java: is there a framework that allows dynamically loading and unloading of jars (but not osgi)?

I want a mechanism that will allow to dynamically load and unload jars as well as calling an activator class in the jar. I don't want to use OSGi because of the cumbersome import/export mechanism. ...

Groovy with Grape and AntBuilder classloader problem

I wanted to use groovy for a little ftp script and found this post http://www.hhhhq.org/blog/2009/05/01/ftp-using-groovy-and-ant/ Since there were several dependencies I wanted to use Grape. All dependencies are resolved and present in the cache. But I can't get Ant to find the optional tasks in the other libs. It always says Caught: : ...

java classloader and runtime compilation

Hi all, Despite warnings to drop my present course of action, I currently see no better way to solve my problem. I must generate Java code at runtime, then compile it, load it and reference it. Problem is that the generated code imports code that has already been loaded by the system class loader (I suppose) - that is, code present in ...

Custom class loader in Constructor.newInstance

I'm using rhino via the bean scripting framework to create and configure objects in my java process. Some of the classes used in the scripts need to be loaded dynamically as they won't always be on the standard classpath. To load these classes I initialize the scripting framework's context factory with a custom class loader that loads t...

Any tool to view the picture of class loader tree?

Say I'm debugging some weird class loading issues of an application deployed inside of a Java EE app server. By some reason it appears, that I have duplicate jars on the class paths of two classloaders (2 different EAR classloaders), and the classes from namespaces of these class loaders need to colaborate. So the question is following:...

Substitute (override) class implementation at Runtime (Java)

Is there any way of substituting (overriding) a Java class implementation, which is already loaded by the System class loader by another implementation (available as an array of bytes)? To illustrate my doubt, follows this code: public class Main { public static void main(String ... args) { Foo foo = new Foo(); foo....

Detect whether Java class is loadable

I have two programs: one CLI program, and one GUI. The GUI is a frontend for the CLI, but also a GUI for another program as well. I am importing the CLI's classes and extending them in the GUI to add GUI elements to the classes, and all is great. But now I want to split the CLI that I currently have embedded in the GUI (as an include...

java FileInputStream - differences based on how the File object is referenced: classloader/filesystem

Hi all, I'm using apache POI to extract some data from an excel file. I need an InputStream to instantiate the POI HSSFWorkbook class HSSFWorkbook wb = new HSSFWorkbook(inputStreamX); I'm finding differences if I try to construct the InputStream object like InputStream inputStream = new FileInputStream(new File("/home/xxx/workspace...

Directory list of JAR file within classpath

The typically method to reference a file contained with a JAR file is to use ClassLoader.getResource. Is there a way to get the contents of a directory within a JAR files (similar to java.io.File.listFiles())? Note that the JAR file is within the classpath and its filename might not be known during runtime. Basically I have a bunch of n...