classloader

Is there a way to force a classloader to load a package even if none of its classes have been loaded?

假装没事ソ 提交于 2019-12-19 05:18:30
问题 Let's say a java codebase has a package called "com.example". At runtime, we can get this Package by calling Package p = Package.getPackage( "com.example" ); //(returns null) or even get a list of all packages by calling Packages[] ps = Package.getPackages(); The problem is - if the ClassLoader has not yet loaded any class from the package, it won't be available to these function calls. We can force it to load the package by force-loading one of the classes in the package first, like this:

Handle multiple JDBC drivers from the SAME VENDOR

空扰寡人 提交于 2019-12-19 03:22:10
问题 I came across with a big problem yesterday. In my current project I use ojdbc6 implementation of Oracle's JDBC for a connection, but also I would need to handle for example oracle 8 databases, which is totally impossible with this JAR. You would say that I should use ojdbc14 for example which was true for some tests, but lets assume that later on I will need to handle 2 kind of databases from the same vendor, but we know that there is no existing implementation for BOTH and I need to have

How to dynamically load class in Objective-C?

懵懂的女人 提交于 2019-12-19 03:14:47
问题 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() = " +

Thread creation listener

那年仲夏 提交于 2019-12-19 02:42:28
问题 Is it possible to write Thread creation listener in java? For example using aop?! I mean something like this that if my application creates a thread I would like to register this object in my own table, container or something. 回答1: I think this would be possible with AOP (aspectj for instance). But it is still required to create your own Thread and ThreadGroup / Executor types, unless you can recompile the JDK classes with the aspect compiler. Define the pointcut on your thread's start method

how to share objects between different classloaders?

泄露秘密 提交于 2019-12-18 18:54:40
问题 I need different classloaders to be able to unload classes. But i need to share objects between them (actually i am getting ClassCastException). So what are the solutions to deal with this?. Thanks 回答1: Objects from different classloaders can interact with each other through interfaces and classes loaded by a common classloader. 回答2: One of the primary objectives of using separate classloaders is to prevent exactly the kind of thing that you are trying to do. Security and name conflicts are

Load external library in java web application

☆樱花仙子☆ 提交于 2019-12-18 17:13:10
问题 My scenario is the following: I have a WebApp.war that is deployed to a servlet container. This WebApp.war contains in WEB-INF/lib the following libraries: lib_a.jar lib_b.jar I have one other library, say lib_vendor.jar, that I cannot deploy within WebApp/WEB-INF/lib because of licensing issues so I let our customers to copy this library in tomcat/lib after application installation. But since lib_vendor.jar requires lib_a.jar and lib_b.jar that are loaded in the web application class loader,

How to determine main class at runtime in threaded java application?

▼魔方 西西 提交于 2019-12-18 14:14:14
问题 I want to determine the class name where my application started, the one with the main() method, at runtime, but I'm in another thread and my stacktrace doesn't go all the way back to the original class. I've searched System properties and everything that ClassLoader has to offer and come up with nothing. Is this information just not available? Thanks. 回答1: See the comments on link given by Tom Hawtin. A solution is these days is (Oracle JVM only): public static String getMainClassAndArgs() {

Java: Dynamically Load Multiple Versions of Same Class

我与影子孤独终老i 提交于 2019-12-18 13:29:50
问题 What I'd like to be able to do is to load set of classes, probably all in the same folder. All of which implement the same interface and are the same class, then in my code I'd like to be able to call functions on those classes. 回答1: Based on your answer to my question, it seems you want to define a game interface and then plug in any number of AI implementations, probably configured from a .properties file. This is fairly standard use of an API interface. You define an EngineInterface

Java: Dynamically Load Multiple Versions of Same Class

爷,独闯天下 提交于 2019-12-18 13:28:04
问题 What I'd like to be able to do is to load set of classes, probably all in the same folder. All of which implement the same interface and are the same class, then in my code I'd like to be able to call functions on those classes. 回答1: Based on your answer to my question, it seems you want to define a game interface and then plug in any number of AI implementations, probably configured from a .properties file. This is fairly standard use of an API interface. You define an EngineInterface

Tomcat Java Servlet - Initialize Class on Application Startup

风流意气都作罢 提交于 2019-12-18 13:24:51
问题 I have a class that takes a bit of time to start up (makes some JNI calls and what not), so it is not feasable to initialize this class everytime a page loads. Is it possible to initialize this class on application startup, then access its methods as pages are being served up? For Example: I have MyClass. When the application (tomcat) starts up I would like it to initialze my calss as follows: MyClass myClassInstance = new MyClass("arg1", "arg2"); Then when a page is called, say /testpage, I