classloader

Loading Resources with the Context Loader fails with a NullPointerException

百般思念 提交于 2019-12-14 03:49:28
问题 I'm just wondering why I cannot load a resource with the Thread context loader in Felix OSGi? Am I not supposed to touch the context loader, am I doing something wrong or is it a bug? I've a super simple bundle with a simple Activator: public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println("Hello World!!"); String resourcePath = "META-INF/mySuperDuperResource.txt"; // works System.out.println(Activator.class

getResources() returns an empty Enumeration

霸气de小男生 提交于 2019-12-13 21:05:33
问题 I'm using a util class (http://pastie.org/private/mxvpdrs3y2xutbjdo68a#11,14,17) to iterate over all classes inside a package. The problem is that getResources("my/package") returns an empty Enumeration even though getResource("my/package/MyClass.class") gives the correct URL for all containing classes ("jar:file:/C:/Users/---/Desktop/Server/plugins/Test.jar!/my/package/MyClass.class"). Usage (in my.test.Reader): List<Class<?>> classes = new ArrayList<Class<?>>(); try { classes = new

Classloader in Applet: Can't access files

℡╲_俬逩灬. 提交于 2019-12-13 19:22:49
问题 I have an application that uses reflection to instantiate code saved in some directory: I create a URLClassLoader that then loads the classes using the URLs provided; this works fine. I tried to port the application to an Applet. For loading text files and images, I changed the code from using relative paths to use getResourceAsStream() which works great. For the class loader, however, I still have an I/O exception (which I also used to get with the text files and images before I changed the

Find a resource (.txt file) in war file which is deployed standalone or in ear

拥有回忆 提交于 2019-12-13 16:55:57
问题 I have a war file is packaged in ear and deployed. Here is the structure: EAR -WAR --input.txt --META-INF --WEB-INF ---classes (and so on) I am trying to read input.txt from one of the classes (say abc.xyz.Myclass) in WEB-INF/classes folder. Here is what I tried: this.getClass().getClassLoader().getResourceAsStream("../../input.txt"); and Thread.currentThread().getContextClassLoader().getResourceAsStream("../../input.txt"); I tried several paths like "../input.txt" or "/input.txt" or just

ClassNotFoundException when deserializing data from cache

纵饮孤独 提交于 2019-12-13 16:12:40
问题 I have an EAR application with EJB for web services, deployed at Glassfish 3.0.1 server. All dependencies are loaded by maven, regarding to pom.xml. I am using wsimport for generate classes from WSDL files. Everything worked perfectly. Then I had to implement caching for mybatis queries because of some performance issues. After I turn caching on, I realize, that my classes need to be serializable. This wasn't a problem. <xs:annotation> <xs:appinfo> <jaxb:globalBindings> <xjc:serializable uid=

run a executable jar file within java program using class loaders

无人久伴 提交于 2019-12-13 15:22:18
问题 I have heard that you could run other java files using Process or using ClassLoaders. I have a executable jar 'test.jar' with a main class called Test . I found a way to run using Process. I need to know how to do it using ClassLoaders. Process p = Runtime.getRuntime().exec("java -jar test.jar"); BufferedInputStream bis = new BufferedInputStream(p.getInputStream()); synchronized (p) { p.waitFor(); } int b=0; while((b=bis.read()) >0){ System.out.print((char)b); } 回答1: The basic approach is to:

Overriding application server behaviour for loading jsp-api and servlet-api jars in a packaged web application

半世苍凉 提交于 2019-12-13 14:57:10
问题 I have a project built and packaged with a specific version of jsp-apiand servlet-api jar files. Now I want these jars to be loaded when deploying the web project on any application server for example tomcat, WAS, Weblogic etc. The behaviour I have seen on tomcat is that it gives messages that the packaged version of these apis are not loaded along with an offending class. Is there any way I could override these server settings or behaviour? My concern is that letting the default behaviour of

Understanding ClassLoaders in Java

依然范特西╮ 提交于 2019-12-13 13:24:42
问题 I'm fairly new to the JVM and ClassLoaders. I have these two classes: public abstract class CoreModule extends Entity public final class EventManager extends CoreModule At the start of the program, I create an instance of EventManager . So I understand that the JVM knows what Entity class is and how to load it (that is, it knows what ClassLoader to use), since EventManager is a grand-child. But when an Entity instance is passed by some serialization mechanism, it throws ClassNotFoundException

UnsatisfiedLink error : opencv_java2411.dll already loaded in another classloader in glass fish

本小妞迷上赌 提交于 2019-12-13 08:54:30
问题 I am implementing a web application for face recognition in java using opencv. While I am running the code for face recognition I am getting errors like java.lang.UnsatisfiedLinkError: Native Library F:\opencv\build\java\x86\opencv_java2411.dll already loaded in another classloader i had done several methods avaliable over internet such as checking whether the class is loaded or not making the system.loadlibrary as static block adding path to environment variable and so on but the error

How to prevent third-party JARs on the classpath from overriding my class dependencies?

自作多情 提交于 2019-12-13 06:13:43
问题 I am writing an application plugin in Java, and my plugin has dependencies on several third-party JARs. I am bundling these dependencies with my plugin so that I can deploy just a single JAR file. The host application may also be running plugins from other vendors. Unfortunately the host application puts all the plugins on the classpath, and I am not able to change this behavior. If another vendor's plugin is loaded before mine and uses an incompatible version of a dependency, my plugin could