classloader

why doesn't this code throw NullPointerException

大兔子大兔子 提交于 2019-12-01 02:59:41
I was just discussing about calling static methods using class name with my friend and tried out this code and expected it to throw NPE at runtime.but as it turn out it dint. i just want to understand the execution order. public class One { public static void method() { System.out.println("in static one"); } } public class Two { static One o; public static void main(String[] args) { o.method(); // expected NPE here, as o is null } } I know that static methods should be invoked with their class name, I even know that IDE's would give a compiler warning when we call static methods with an

Custom Tomcat Valve contained in web app WAR file

◇◆丶佛笑我妖孽 提交于 2019-12-01 02:23:33
问题 I'm looking to implement a custom Valve and configuring it using META-INF/context.xml. At the moment though, when context.xml is parsed during deployment, Tomcat (6.0.32) dies with a ClassNotFoundException on my custom Valve implementation. I'm under the impression that I'm running into a class loading context issue and I'm not 100% sure I understand it. Is my class not found because it is located in the WEB-INF/classes file and the Context level class loader is unable to locate the class

Java classLoader dilemma with locked jars

こ雲淡風輕ζ 提交于 2019-12-01 02:16:48
问题 I was playing around with classLoaders in Java and noticed a strange thing. If a classLoader loads a class from a jar, this jar is locked indefinitely even if you unreference your classLoader. In the below example, the jar contains a class called HelloWorld. What I do is try to load the class contained in the jar via a classLoader which adds the jar dynamically. If you set skip to true and do not call Class.forName , you can delete the jar but if you do not skip and even if you unreference

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

大憨熊 提交于 2019-12-01 00:49:45
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 across multiple beans? I am looking for cache within JVM. (Not the remote e.g memcached etc.). Glassfish is used as an application server. I haven't been able to test it yet, but I think that one of the techniques explained in the "Circumventing Class Loader

Dynamically loading Jar and instanciate an Object of a loaded Class

喜欢而已 提交于 2019-12-01 00:24:41
I try to load dynamically a jar into my Java project. Here's the class loader's code : public class ClassLoad { public static void main(String[] args) { String filePath = new String("C:/Users/Mehdi/Desktop/JavaClassLoader/jarred.jar"); URL myJarFile = null; try { myJarFile = new URL("file://"+filePath); } catch (MalformedURLException e1) { System.out.println("1"); e1.printStackTrace(); } URLClassLoader cl = URLClassLoader.newInstance(new URL[]{myJarFile}); Class Jarred = null; try { Jarred = cl.loadClass("com.jarred.exp.Jarred"); } catch (ClassNotFoundException e) { System.out.println("2"); e

ProviderImpl not found Jboss 5.1

走远了吗. 提交于 2019-11-30 23:21:16
I use jaxws 2.2.3 and Jboss 5.1 with JDK 6. When calling ws client, I get java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider org.jboss.ws.core.jaxws.spi.ProviderImpl not found (see full stack trace below) When I remove libs jbossws-native-*.jar from jboss/lib/endorsed everthing works fine. But they must be there. I tried to tell jboss to use com.sun.xml.ws.spi.ProviderImpl: META-INF/services/javax.xml.ws.spi.Provider -Djavax.xml.ws.spi.Provider to read first my libs WEB-INF/jboss-classloading.xml <classloading xmlns="urn:jboss:classloading:1.0" parent-first="false" domain

Overriding single classes from rt.jar

好久不见. 提交于 2019-11-30 22:53:38
I'm looking for a neat way to override a class from the bootstrap class path, rt.jar . The reason is OpenJDK7 bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7104625 The fix for this bug is a trivial (see linked mailing list post) change to sun.awt.X11.XComponentPeer . So I was wondering if there is an easy way to override just this one affected class on my classpath, without having to repack/rebuild rt.jar (so the fix isn't lost on the next automatic update of OpenJDK). Ideally, it would also affect Eclipse... I assume that java -Djava.system.class.loader=myClassLoader would work? Is

URLClassLoader loads Annotation as com.sun.$Proxy$27

牧云@^-^@ 提交于 2019-11-30 22:39:46
I'm trying to dynamically load a java class. The basic idea is, that a jar contains modules which get loaded dynamically at runtime. This is how I do it (I know it's hacky, but there is no other method to dynamically add a jar to an already existing classloader afaik): Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); method.invoke(moduleLoader, new Object[] { file.toURI().toURL() }); Class fooClass = moduleLoader.loadClass("com.coderunner.Foo"); Object foo = fooClass.newInstance(); Every module is annotated with an @Module

Problem loading resources while running in Eclipse

岁酱吖の 提交于 2019-11-30 22:14:16
I'm working on a swing project, using maven2 (from command-line) and eclipse (without maven integration). So, I generate the eclipse project through maven eclipse plugin ( mvn eclipse:eclipse ), import it inside eclipse, and do all my work. My problem is: when I run my app in eclipse (as a Java Application), I can't find none of the resources that are in my src directory. Digging for information on my problem, I get into this answer from another question . So, I compared the output from the following instructions: MyClass.class.getResource("/").getPath(); MyClass.class.getProtectionDomain()

How to dynamically load class in Objective-C?

喜欢而已 提交于 2019-11-30 21:50:22
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){ ClassLoader classLoader = MainClass.class.getClassLoader(); try { Class aClass = classLoader.loadClass("com.jenkov.MyClass"); System.out.println("aClass.getName() = " + aClass.getName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } } which function in