classloader

ClassLoader getResourceAsStream returns null

不羁的心 提交于 2019-12-17 10:57:08
问题 My project directory structure (in Eclipse): MyProject/ src/ --> "source directory" on Eclipse's classpath/buildpath com.me.myapp Driver myconfig.txt In Driver , I have the following code: public class Driver { public static void main(String[] args) { InputStream is = ClassLoader.getSystemClassLoader.getResourceAsStream("myconfig.txt"); if(is == null) System.out.println("input stream is null"); else System.out.println("input stream is NOT null :-)"); } } When I run this I get the following

Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Logger

浪子不回头ぞ 提交于 2019-12-17 10:39:13
问题 I've got an interesting problem in which the org.apache.log4j.Logger class is not found during runtime. I'm trying to get authorized and that is where it's failing: OAuthAuthorizer oauthAuthorizer = new OAuthAuthorizer(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, SAML_PROVIDER_ID, userId); I'm using JDeveloper 11.1.1.6. Here is what I know: I've looked in my UI.war/WEB-INF/lib directory and I see the log4j-1.2.17.jar there. The class complaining about it is org.opensaml.xml.XMLConfigurator

Java: How to load Class stored as byte[] into the JVM?

▼魔方 西西 提交于 2019-12-17 10:37:17
问题 If one has serialized the entire .class file into byte[], and assuming the name of the class is known (passed along with the byte[]), how do you convert byte[] -> Class -> then load it to the JVM so that I could later use it by calling the Class.forName()? NOTE: I'm doing this because I sent the .class over to another host, and the host's JVM doesn't know about this .class. 回答1: I'm actually using something like this right now in a test to give a set of Class definitions as byte[] to a

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

纵然是瞬间 提交于 2019-12-17 10:33:49
问题 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 classes that won't even be used. I don't really understand class loaders that well so this might not be a problem. Is there a way to take a peak at all the

Java 9, compatability issue with ClassLoader.getSystemClassLoader

血红的双手。 提交于 2019-12-17 09:51:36
问题 The following code adds jar file to the build path, it works fine with Java 8. However, it throws exception with Java 9, the exception is related to the cast to URLClassLoader. Any ideas how this can be solved? an optimal solution will edit it to work with both Java 8 & 9. private static int AddtoBuildPath(File f) { try { URI u = f.toURI(); URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class<URLClassLoader> urlClass = URLClassLoader.class; Method method

Replacement System Classloader for Classes In Jars containing Jars

怎甘沉沦 提交于 2019-12-17 07:29:56
问题 So far, the examples I have seen for custom ClassLoaders involve subclassing the URLClassLoader, and using that specific instance to load classes in resources. I have tried in vain to look for alternative methods to replace the SystemClassLoader, so that my ClassLoader can be consulted for classes not located in the classpath. I tried Thread.currentThread().setContextClassLoader , but it doesn't seem to work. Is it even possible? 回答1: Though this is an old question, there is indeed a way to

Singleton class with several different classloaders

断了今生、忘了曾经 提交于 2019-12-17 02:29:38
问题 E.g I have class Singleton with static field instance : public class Singleton { private static Singleton instance; // other code, construct, getters, no matter } I can load this class twice with two different classloaders. How could I avoid it? It is unsafe and dangerous. Also, if I set instance to null, would it set to null for both classes? Singleton singleton = Singleton.getInstance(); singleton = null; 回答1: If you want a true Singleton across classloaders, then you need a common parent

Websphere httpclient NoSuchMethodError org.apache.http.conn.Scheme

吃可爱长大的小学妹 提交于 2019-12-14 04:09:44
问题 I'm seeing the same issue as posted in this thread NoSuchMethodError org.apache.http.conn.scheme.Scheme I would like to use httpclient-4.2.5 and tried using an isolated shared library as suggested in the previous post. (shared library was associated to the app, 2 jars (httpclient-4.2.5.jar and httpcore-4.2.4.jar) were added to the shared lib) However, it seems to still be loading some classes from com.ibm.ws.prereq.jaxrs.jar Is there a step I'm missing in setting up the shared lib? 回答1: You

How to manually add ClassLoader in Laravel 5

岁酱吖の 提交于 2019-12-14 03:55:51
问题 I want add my class to classloader by this commands $loader = new \Composer\Autoload\ClassLoader(); $loader->addPsr4('test\\', __DIR__ . '/../..' . '/modules/test'); $loader->register(); but dose not work and no error dd($loader) : ClassLoader {#470 ▼ -prefixLengthsPsr4: array:1 [▼ "t" => array:1 [▶] ] -prefixDirsPsr4: array:1 [▼ "test\" => array:1 [▼ 0 => "C:\wamp\www\app\Http\Controllers\admin/../../modules/test" ] ] -fallbackDirsPsr4: [] -prefixesPsr0: [] -fallbackDirsPsr0: []

Java classloader usage in OSGi

那年仲夏 提交于 2019-12-14 03:54:44
问题 I have a question about the usage of Java ClassLoader in OSGi. I wrote two OSGi bundles, namely server bundle and client bundle. In server bundle, I implemented BundleActivator like: public class Activator implements BundleActivator { public void start(BundleContext context) { System.out.println("[Server:Activator.java:26] " + Activator.class.getClassLoader()); context.registerService(HelloService.class, new HelloService(), null); } public void stop(BundleContext context) { System.out.println