classloader

Do I have a JAXB classloader leak

I have an application deployed on Glassfish. Over time the number of loaded classes climbs into the millions and my permgen seems to rise. To help troubleshoot I added the following to my jvm arguments. -XX:+PrintGCDetails -XX:+TraceClassUnloading -XX:+TraceClassLoading Now when watching the output, I see the same classes being loaded ...

sysLoader.getResource() problem in java

Hi all, I am having following lines of code. sysLoader = (URLClassLoader)Thread.currentThread().getContextClassLoader(); url = sysLoader.getResource("tempFile.txt"); It is giving an weird problem. If I run this from a path where there is no space in the path (Folder names) then it is running fine. But if the path contains any spaces ...

JRubyClassLoader not getting released

We're running a small JRuby on Rails app under Tomcat 6.0.28 with a Spring-based backend. I've spent some time with the Eclipse Memory Analysis tool and I can definitely tell that instances of the JRubyClassLoader are leaking. I setup our webapp to only use a single JRuby runtime and then I effectively did a hot-deploy to Tomcat by touch...

maven classpath generation for deployment and test

I have a module that is used by creating a custom class loader. The class loader should therefore be created with the path to the module and also all dependencies. I'm looking for a way to make it productive to work with this mechanism in both dev and production environments. I thought the build can generate two files listing all de...

loading shared classes in application javaee5

I am trying to load some classes that are common to all the web applications of my ear in a java ee 5 application. I tried to do this by putting the classes (not jar) in a) directory called "lib" b) also specifying in application.xml's <module><java>lib/common.jar</java></module> and was not successful by either option a or b...

Why would a Java application that uses reflection be unable to fully load a class using Groovy

I am working with a learning management system that runs on JBoss, using JDK 1.5_18. There is a way to write classes that it will load at runtime, using reflection, in order to react to set events. When I write the class in POJO the application will successfully find the class. I am always using the full name of the class, and I ensur...

What does JVM flag CMSClassUnloadingEnabled actually do?

Hi I cannot for the life of me find a definition of what the Java VM flag CMSClassUnloadingEnabled actually does, other than some very fuzzy high-level definitions such as "gets rid of your PermGen problems" (which it doesn't, btw). I have looked on Sun's/Oracle's site, and even the options list doesn't actually say what it does. Base...

Loading classes not present in the classpath

Let's say I've compiled a Groovy script using Groovyc, which has generated one or more .class files in the file system. From a Java application, how do I add those classes to the classpath dynamically in order to load them and call their methods? The goal is to pre-compile Groovy scripts and store them into the database, so evaluation ca...

Dynamic Jar loading is confusing me

Conceptually, what am I doing when I'm loading a new Jar? Is URLClassloader the only choice? How should I form those URLs to point to a subdirectory containing more jars. If anyone is feeling super-generous, some demonstration code to do the following would be really helpful (let's assume "jars/A.jar" contains "myClass" which we want t...

Why doesn't jrunscript honor my classpath?

I'm trying to do some JDBC access from JavaScript using the Rhino included in Java 6. But I cannot make the DriverManager find the Driver I want to use. These two examples should be equivalent: Java: public class DbTest { public static void main(String[] argv) { java.sql.Connection c = null; try { java....

Do I need to create custom ClassLoaders to support new archives format?

I need to support loading classes from other types of archives(tar.gz,tar.bz2...) and custom types defined by third parties. Do I need to override the 'loadClass' method to achieve that? (Perhaps theres another extension point for doing this? I still want to benefit from all the security checks made by the default class loaders). ...

Java Custom Class Loader

Any ideas why I am getting this error? (Yes, I looked up the error, and still haven't found a solution) My error: Exception in thread "main" java.lang.ClassFormatError: Truncated class file at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.lang.ClassLoader.defineClass(...

Trouble creating cutom class loader

I am trying to create a custom class loader to accomplish the following: I have a class in package com.company.MyClass When the class loader is asked to load anything in the following format: com.company.[additionalPart].MyClass I'd like the class loader to load com.company.MyClass effectively ignoring the [additionalPart] of the pac...

Why am I having trouble accessing a .properties file in a standalone instance of tomcat but not in an eclipse-embedded instance?

I wrote a simple Hello World Servlet in Eclipse containing the following in the doGet method of my HelloWorldServlet.java PrintWriter writer = response.getWriter(); String hello = PropertyLoader.bundle.getProperty("hello"); writer.append(hello); writer.flush(); PropertyLoader is a simple class in the same package as the Servlet th...

How to dynamically compile and load a Java class that complies to an interface at runtime?

I'm trying to compile and load a class at runtime, without knowing the package of the class. I do know that the class should comply with an interface, and the location of the source, (and hence the class name). I'm trying the following: /* Compiling source */ File root = new File("scripts"); File sourceFile = new File(root, "Test.java"...

Why does Class.getPackage return the same Package for classes from different packages?

I make a new ClassLoader and make it define a new Class, which means that new class should be in a new namespace, which it is, AFAIK. The strange thing is, when I call Class.getPackage on the new class, it returns the exact same object as returned by calling getPackage on any other class in my main namespace. According to the JVM spec: ...

Strange behavior of EnumMap with keys from different classloaders

I encountered strange behavior of enum type loaded by different class loader. In common library I have enum definition (similar to the following): enum MyEnumType { VAL_1, VAL_2, VAL_3 }; I have first application which creates following map and registers it as some kind of global in the system (the registration code is only symbolic f...

Classloader problem with EJB

Hi! I'm working on a project which includes persistence library (JPA 1.2), EJB 3 and Web presentation layer (JSF). I develop application using Eclipse and application is published on Websphere Application Server Community Edition (Geronimo 2.1.4) through eclipse plugin (but the same thing happens if I publish manually). When publishing ...

Check if class exists in Java classpath without running its static initializer?

If I use try { Class.forName("my.package.Foo"); // it exists on the classpath } catch(ClassNotFoundException e) { // it does not exist on the classpath } the static initializer block of "Foo" is kicked off. Is there a way to determine whether a class "my.package.Foo" is on the classpath without kicking off i...

Java or any other language: Which method/class invoked mine?

I would like to write a code internal to my method that print which method/class has invoked it. (My assumption is that I can't change anything but my method..) How about other programming languages? EDIT: Thanks guys, how about JavaScript? python? C++? ...