classloader

Forcing class load

空扰寡人 提交于 2019-12-04 17:21:02
问题 Is there a way in C# or .net IL to force a class that has a type initializer (static constructor) to load itself, without accessing any of its parameters? Assuming I've got the class public static class LogInitialization { static LogInitialization() { System.Console.WriteLine("Initialized"); } } Is there a way to get this line to print? Note that the class is static so I can't instantiate it to force initialization, and it has no public members so I can't access them to start it. 回答1:

How can i check if android device supports a library?

冷暖自知 提交于 2019-12-04 17:15:40
I created an Android application with IR blaster and I want my code to check if an Android device supports these libraries. When another device installs my app, it crashes. How can I avoid this? I want my code to get info about whether the phone supports my app. This is a similar problem to loading JDBC drivers. If the drivers don't exist you don't want to crash out your entire app. The basic principle of the solution is to use Class.forName() This lets you check if the class exists and throws an exception if it doesn't. Edit: To be clear - the reason why this works and why this is necessary

Access project classes from a maven plugin

微笑、不失礼 提交于 2019-12-04 17:13:53
I'm making a maven plugin that run in test phase, in pom.xml configuration of a project that uses my plugin, I'm setting a class canonical name that I want to use to run that class from my plugin, basically I'm making a way to have a dynamic class loading of classes inside the project from my plugin. Class clazz = Class.forName("... class from pom.xml ...") When I run it I receive the expectable "ClassNotFoundException", seems the class loader are not the same or not shared. There is a way to do it? Like capture the class loader from the project or receive it by dependency injection into my

Parent Last Classloader to solve Java Class path hell?

好久不见. 提交于 2019-12-04 16:54:56
I have a project which uses two versions of bouncyCastle jars bcprov-jdk15 and bcprov-jdk16. The jvm loads the older version but there is a feature I wrote which needs the newer version to run. I tried to solve this classpath hell by using a custom class loader. After some googling and with the help of some previous Stackoverflow answers [1] [2] and this blog , I wrote the following Parent Last Class loader to load the classes from the newer jar before delegating to the parent class loader. public class ParentLastClassLoader extends ClassLoader { private String jarFile; //Path to the jar file

Tomcat6 ignores web-inf/lib

痴心易碎 提交于 2019-12-04 15:54:05
Brief: Tomcat6 can't recognize my ojdbc14.jar in WebRoot/WEB-INF/lib. I suppose I don't need to configure anything, just putting the .jar file in there and it should work. Details: I've created a web application and put ojdbc14.jar in WEB-INF/lib folder. When I start Tomcat6 and access an index.jsp page which creates an object that initiates a connection to my oracle database , an error occurs saying "Cannot load JDBC driver class 'oracle.jdbc.OracleDriver'". Apparently Tomcat6 can't recognize the 'oracle.jdbc.OracleDriver' class in web-inf/lib/ojdbc14.jar . I've done some research and

deployment.xml for WebSphere and Maven

最后都变了- 提交于 2019-12-04 15:53:20
I've converted an application to be built and deployed with Maven instead of RAD's built-in tools. It's mostly gone well, but the last "gotcha" is that the application needs a class loader policy of "parent last/application". I'd like to automate this because currently, when I use the WAS plugin for Maven , it seems to uninstall and reinstall the application completely, and so I have to go through the admin console every time the code changes and the application is redeployed. If I could have the class loader settings built in to the deployed EAR, work would go much faster. From what I can

Is it possible to force someone else's java ClassLoader to load an external byte array containing the bytecode of a valid Java class?

▼魔方 西西 提交于 2019-12-04 15:52:34
I'm trying to force the System java classloader (i.e. ClassLoader.getSystemClassLoader() ) to load an external class defined by a byte array with valid bytecode so that other classes subsequently loaded by this classloader can know about and instantiate the external class without getting a NoClassDefFoundError . This surely does not work as it only defines the class on the classloader created, not in the System classloader: URLClassLoader child = new URLClassLoader(new URL[] { myJar.toURI().toURL() , ClassLoader.getSystemClassLoader()); Class.forName ("com.MyClass", true, child); The code

How to config socks proxy in Java NIO

匆匆过客 提交于 2019-12-04 15:10:14
问题 I'm developing a tool which includes forcing all network traffic of application to go across a socks proxy in Java. For old Socket API, I can just set system properties "-DsocksProxyHost=my-host -DsocksProxyPort=my-port", but it doesn't work with NIO. I tried a solution: I wrote an NIO SocketChannel, called "ProxySocketChannel" which extends SocketChannel. It contains socks connection and other socks proxy logic. But when I run it, I got an "IllegalSelectorException" in this line of code in

Jboss 4.2 Class Loading

落爺英雄遲暮 提交于 2019-12-04 14:53:54
I have a jar in server/default/lib which contains Foo.class , Bar.class and the same class is there in my application/WEB-INF/classes which is deployed in server/default/deploy . and Example.class is using the Foo.class instance and Bar.class instance Now the situation is that Example.class shoud use the Foo.class in my application and Bar.class in default/lib jar file. i.e. my application should use the classes in the application clases folder if not found in classes folder then it should use the class in default/lib jar files. To do i have defined jboss-web.xml file <jboss-web> <class

Runtime code generation and compilation

 ̄綄美尐妖づ 提交于 2019-12-04 14:50:53
Say I have this code that uses some input (e.g. a URL path) to determine which method to run, via reflection: // init map.put("/users/*", "viewUser"); map.put("/users", "userIndex"); // later String methodName = map.get(path); Method m = Handler.class.getMethod(methodName, ...); m.invoke(handler, ...); This uses reflection so the performance can be improved. It could be done like this: // init map.put("/users/*", new Runnable() { public void run() { handler.viewUser(); } }); map.put("/users", new Runnable() { public void run() { handler.userIndex(); } }); // later Runnable action = map.get