classloader

What are some interesting uses for Java Agents?

Starting with Java 5 there's an option to add Java Agents to the class loader. Have you written any Agents? have you used any Agents? What are interesting uses of Agents? ...

How can I programmatically find the full path of the main executing class.

I'm trying to local a properties file programmatically without having to pass it's fullpathname on the commandline to my program. I figure if I can locate the path of the main class, I can stick my properties file in the same directory or a sub-directory. If that won't work is there some other way I can locate the path of a properti...

Control class loading order in Java

Hi, I've created a class which holds a bunch of properties values. In order to initialize that class, I have to call some static method "configure()" which configures it from an XML file. That class was supposed to act to store some data such that I could just write PropClass.GetMyProperty(); I call the configure() from a static b...

classloader.getSystemResourceAsStream returns null

Hi everyone, I'm trying to load a properties file without using the actual path of the file. I've already done that on some other simple apps using: InputStream inputStream = ClassLoader.getSystemResourceAsStream(PROPERTIES_FILE); props.load(inputStream); But this time it doesn't work. The inputStream is null for some reason. PROPERT...

Where on the file system was my java class loaded from?

I think this is a situation every java programmer runs into if they do it long enough. Your doing some debugging and make a changes to class. When you go to re-run the program, these changes don't seem to be picked up but rather the old class still seems to be running. you clean and rebuild everything, same issue. Sometimes, this can...

Can I set the classloader policy for WebSphere in the ibm-web-bnd.xmi file?

I have a JEE application that runs on WAS 6. It needs to have the class loader order setting to "Classes loaded with application class loader first", and the WAR class loader policy option set to "Single class loader for application". Is it possible to specify these options inside the EAR file, whether in the ibm-web-bnd.xmi file or so...

How can I get around this classloader hierarchy problem?

I run iplanet's java applcation server, something in it is loading commons-logging-1.0.4.jar That's fine until one of my applications calls AuthSSLProtocolSocketFactory which is another apache library that also uses commons logging. I put the jar on the jvm classpath and get this error Invalid class loader hierarchy. You have more tha...

adding relative directory to java classpath and using ClassLoader().getResourceAsStream("")

Is it possible to add a relative directory (ie, foo/bar/plugh) to the java classpath and use InputStream in = getClassLoader().getResourceAsStream("xyzzy.properties"); To fetch foo/bar/plugh/xyzzy.properties? My classpath looks like this: foo.jar;foo/bar/plugh;xyz.jar And I am able to use classes and resources from both foo and x...

Applet class loader cannot find a class in the applet's jar

I started to ask this question and then figured out the answer before submitting it. I've decided to post the question anyway so that other people who run into the same problem will be able to learn from my mistakes. I'm having a problem with an applet (a JApplet actually) unable to instantiate another class which is included in the s...

Finding Display of an RCP App

I'm writing a testing Framework which is starting a GUI Application. To be able to test this GUI in the case of an SWT application I need to know it's display. In general, this display is loaded by another classloader, therefore I'm using the method findDisplay(Thread t) of the swt Display class by reflection to accomplish this task. My ...

Using the ClassLoader method to retrieve all resources under classes as Input Streams

Hello there, My problem is one that you would think is quite common, but I haven't so far managed to find a solution. Building a Java web app under Tomcat 5.5 (although a requirement is that it can be deployed anywhere, like under a WebLogic environment, hence the loading resources as streams requirement). Good practice dictates that r...

How to determine main class at runtime in threaded java application?

I want to determine the class name where my application started, the one with the main() method, at runtime, but I'm in another thread and my stacktrace doesn't go all the way back to the original class. I've searched System properties and everything that ClassLoader has to offer and come up with nothing. Is this information just not a...

Use a custom classloader at compile time

Is it possible to specify a custom classloader for javac (or some alternative java compiler)? I'd love such a feat because it would allow me to compile classes that use classes that are only found by my special classloader. For the curious once: I'd write a classloder that connects to a database and creates classes based on the tables...

How to explore which classes are loaded from which JARs?

Is there a way to determine which classes are loaded from which jars at runtime? I'm sure we've all been in JAR hell before. I've run across this problem a lot troubleshooting ClassNotFoundExceptions and NoClassDefFoundErrors on projects. I'd like to avoid finding all instances of a class in jars and using process of elimination on the...

Loading Java Classes which arent needed.

I'm currently wondering what the actual overhead, in the JVM, is for loading extra classes which are never used. We have code which iterates all the classes in the class path to find classes which implement a certain interface, we then load them. This allows custom classes to be simply dropped in a directory and they get loaded and reg...

Can i deny access to a jvm class by configuring java.policy file ?

I wanted to create add to my jdk6\jre\lib\security\java.policy file an interdiction to create some classes that are blacklisted by appengine. For example I want my local jvm to throw an exception when the application tries to instantiate javax.naming.NamingException. It is possible? I will try to explain my specific problem here. Googl...

How do I get a list of all package names loaded by the JVM

I need to get names of all java packages loaded by the JVM. This is to display a package browser like the ones found in IDEs. I can get the package list of the current classloader and its ancestors by accessing protected "packages" field of the ClassLoader class. But i'm unable to get the packages loaded by other webapps as they have the...

Groovy rootLoader is null

When running a groovy script from Eclipse, the following line: def rootLoader = this.class.getClassLoader().getRootLoader() is null. When I run the script directly from command line, this is not null. How can I find out why this happens? ...

Strange Classpath, .NoClassDefFoundError errors

Edited: SOLUTION FOUND. This is strange and not the best solution, but I just went ahead and put MY JAVA CODE (com.*) the classes in the swt.jar so that swt.jar and my classes are loaded at the exact same moment and by the same classloader. Not the best solution but a temporary fix Edited: I added most of the code here: http://groups...

Loading .jars during runtime: my loader works, but using setContextClassLoader doesn't?

Hello, I have an URLClassLoader named "MyClassLoader" set up with some jars on it. If I try MyClassLoader.loadClass("MyClass"); it works. If I try Thread.currentThread().setContextClassLoader(MyClassLoader); Thread.currentThread().getContextClassLoader().loadClass("MyClass"); it also works. But If I try Thread.currentThread().s...