bcel

Change classloader

蹲街弑〆低调 提交于 2019-11-29 01:58:25
I'm trying to switch the class loader at runtime: public class Test { public static void main(String[] args) throws Exception { final InjectingClassLoader classLoader = new InjectingClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); Thread thread = new Thread("test") { public void run() { System.out.println("running..."); // approach 1 ClassLoader cl = TestProxy.class.getClassLoader(); try { Class c = classLoader.loadClass("classloader.TestProxy"); Object o = c.newInstance(); c.getMethod("test", new Class[] {}).invoke(o); } catch (Exception e) { e.printStackTrace(); } //

Change classloader

喜夏-厌秋 提交于 2019-11-27 16:16:12
问题 I'm trying to switch the class loader at runtime: public class Test { public static void main(String[] args) throws Exception { final InjectingClassLoader classLoader = new InjectingClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); Thread thread = new Thread("test") { public void run() { System.out.println("running..."); // approach 1 ClassLoader cl = TestProxy.class.getClassLoader(); try { Class c = classLoader.loadClass("classloader.TestProxy"); Object o = c

Create simple POJO classes (bytecode) at runtime (dynamically)

旧巷老猫 提交于 2019-11-26 18:56:58
I've the following scenario.. I am writing some tool that run user-entered query against the database and return the result.. The simplest way is to return the result as: List<String[]> but I need to take this a step further. I need to create (at runtime ) some POJO (or DTO) with some name and create fields and setters and getters for it and populate it with the data returned and then return it to the user among with the .class file generated... So the idea here is How to Create simple class(bytecode) at runtime (dynamically) I do a basic search and found many lib including Apache BCEL But I

Create simple POJO classes (bytecode) at runtime (dynamically)

 ̄綄美尐妖づ 提交于 2019-11-26 06:41:40
问题 I\'ve the following scenario.. I am writing some tool that run user-entered query against the database and return the result.. The simplest way is to return the result as: List<String[]> but I need to take this a step further. I need to create (at runtime ) some POJO (or DTO) with some name and create fields and setters and getters for it and populate it with the data returned and then return it to the user among with the .class file generated... So the idea here is How to Create simple class