classloader

Getting a list of all the bootstrap classes on the JVM?

送分小仙女□ 提交于 2019-12-23 19:43:35
问题 There is a method called findBootstrapClass for a ClassLoader that returns a Class if it is bootstrapped. Is there a way to find classes has been loaded? 回答1: You could try to first get the bootstrap class loader by e.g. calling ClassLoader bootstrapLoader = ClassLoader.getSystemClassLoader().getParent(); and then get the classes of this class loader as explained here: How can I list all classes loaded in a specific class loader. But note, that getting the bootstrap class loader is not

How to prefer JARs from Weblogic domain over those from weblogic system

半世苍凉 提交于 2019-12-23 18:43:50
问题 I am using Weblogic Server 12.1.1 and copied some JARs to my domain's lib folder. One of the JARs is a org.apache.commons.io jar. Now I have the problem that Weblogic itself comes with a different version of commons-io in its system classpath and so I get NoSuchMethodErrors . Is there any way to configure Weblogic to prefer the libs from domain over those from Weblogic system? The Filtering Classloader works only on those JARs provided with the application ( WEB-INF/lib ). 回答1: If you need to

How to use implementation loaded with different Java classloader?

老子叫甜甜 提交于 2019-12-23 17:00:57
问题 I am writing a library where I allow people to provide implementations of certain interfaces using a plugin framework (it's JPF if you're familiar). The plugins are not stored in the classpath. The framework gives me a ClassLoader for each plugin, so when implementation named "MyImpl" of interface "MyInterface" is requested, I can find the correct plugin, and then use that plugin's ClassLoader to load the class, from which I can make an instance if I know something about the constructor. So

static block is called twice, maybe multiple class loaders?

痞子三分冷 提交于 2019-12-23 16:15:59
问题 I have an MDB EJB, with static block inside it. I used the static block to initialize some components only once at the first time the application runs (i.e at deployment). The MDB EJB is deployed on a separate sever (My_Server) other than the Admin_Server. The problem is that the static block is called twice! The first time: just after deploying the MDB EJB (tageted to the My_Server). The second time: after the JMS queue (that the MDB is associated with) receives a message. Also, I printed

How to call a method from loaded class using classLoader?

删除回忆录丶 提交于 2019-12-23 15:29:54
问题 This is the code I use : File urlclasspath = new File("C:/Users/ASUS/Desktop/semantics/semantics/bin"); URL urlarray[] = new URL[1]; urlarray[0] = urlclasspath.toURI().toURL(); MyClassLoader mycl = new MyClassLoader(urlarray); Class myclass = mycl.loadClass("USAGE"); Object obj = myclass.newInstance(); And the class I'm loading is USAGE and the method I want to call is main(String[] args) 回答1: You don't need to call newInstance() . Do this: Class<?> myclass = mycl.loadClass("USAGE"); // get

How to use PowerMock with Arquillian?

狂风中的少年 提交于 2019-12-23 12:35:07
问题 I tried to use PowerMockRule in a JUnit test that uses arquillian but I get java.lang.ExceptionInInitializerError Caused by: java.lang.IllegalStateException: PowerMockRule can only be used with the system classloader but was loaded by ModuleClassLoader for Module I want to test something like this: @RunWith(Arquillian.class) @PrepareForTest(WARRRAworkffsTest.class) public class WARRRAworkffsTest { @Rule public PowerMockRule rule = new PowerMockRule(); @Deployment(testable=true) public static

Get bytes for a class that was generated at runtime

人走茶凉 提交于 2019-12-23 10:20:32
问题 I am working with a Java framework that generates some (proxy) classes at runtime, using a custom ClassLoader. I would like to get for any such class that the custom ClassLoader returns from loadClass(..) the raw byte array that corresponds to this class. Is this possible? I know that if a class exists as a resource then you can use an input stream to load the class in binary format but how can I go about this if the class is generated at runtime? 回答1: Register a ClassFileTransformer. Rather

Why can a class not be unloaded without unloading the classloader?

一笑奈何 提交于 2019-12-23 10:06:30
问题 The answer to 'unloading classes in java' says - "The only way that a Class can be unloaded is if the Classloader used is garbage collected." I took a look at the JLS but couldn't understand it Why is this the case? 回答1: A class is only unloaded when it is garbage collected, and for that to happen there must be no references to it anywhere. And the classloader keeps a reference to each class it loads. 来源: https://stackoverflow.com/questions/2551276/why-can-a-class-not-be-unloaded-without

GroovyClassLoader call to parseClass is successful, even when code does not compile

自闭症网瘾萝莉.ら 提交于 2019-12-23 09:43:24
问题 I'm trying to dynamically load a Groovy script as a class but the class object is created even when the script's code does not compile. For example, a simplified version of my Groovy code to load the Groovy script is as follows: GroovyCodeSource src = new GroovyCodeSource( "blah blah blah", "Foo.groovy", GroovyShell.DEFAULT_CODE_BASE ) new GroovyClassLoader().parseClass(src, true) Clearly, the code blah blah blah isn't a legitimate Groovy script. And yet, a class object is successfully

How to use Groovy dynamic objects to call methods requiring concrete types (without referencing them)

柔情痞子 提交于 2019-12-23 02:34:56
问题 Given the following code: def model = readMavenPom file: 'pom.xml' dep = [ groupId : "org.foo", artifactId : "bar", version : "1.0" ] I would like to call Model.addDependency model.addDependency(dep) This gives the error Caught: groovy.lang.MissingMethodException: No signature of method: org.apache.maven.model.Model.addDependency() is applicable for argument types: (java.util.LinkedHashMap) values: [[groupId:org.foo, artifactId:bar, version:1.0]] Now it is possible to do model.addDependency