classloader

Obtaining a list of all Java classes used from all JVM's?

爷,独闯天下 提交于 2019-12-12 21:31:40
问题 I want to have a list of all the classes that are loaded within multiple threads/JVM's at a certain moment in time. I know that when you run java with the -verbose parameter, you can write it to a file as something like this: java -verbose:class com.package.Foo > classes-used.txt However, I have threads in my main program that use a shell script to start a new jar. I would like to avoid to have to write the -verbose parameter in every shell script and I'm wondering if there is any other way

How to load an arbitrary java .class file from the filesystem and reflect on it?

南楼画角 提交于 2019-12-12 21:04:32
问题 I want to make a command-line utility that does some operations based on reflection of external class files. I would pass in a path to .class files or source files(possibly wildcards). At some point during the execution, I need to get Class objects for each class, not knowing their package names beforehand. What would it take to do this? What can I look at to get started? I also have access to the classes' source files. this is in java 1.6. also, would it be easier to get class objects from

Class.forName() and ClassNotFoundException

Deadly 提交于 2019-12-12 20:03:59
问题 Say I have the following two classes: public class MyClass { public String getDescription() { return "MyClass"; } } and public class MyClassLoader { public static void main (String[] argv) throws ClassNotFoundException { Class.forName("MyClass"); System.out.println("MyClass class was successfully loaded"); } } If both of these classes are in the default package, it runs fine, the class loads, and the world is beautiful. (If I were to delete the class MyClass , I would get a

Spring: Is lazy initialization preventing class to be loaded?

只谈情不闲聊 提交于 2019-12-12 18:17:28
问题 Assume I have: <bean id="a1_beanId" class="com.rudziankou.MyUnusedClass" lazy-init="true" > </bean> I have never use this bean during app run. Questions: Will com.rudziankou.MyUnusedClass be loaded by Class Loader ? Do we have access to change default spring class loading behavior? 来源: https://stackoverflow.com/questions/38694980/spring-is-lazy-initialization-preventing-class-to-be-loaded

Need help understanding JNDI and a particular ClassCastException in J2EE

与世无争的帅哥 提交于 2019-12-12 12:27:22
问题 I have an enterprise application A and B deployed (in WLS 10.0). A is the "framework", B is a client app. The client issues the following calls: Object o = ctx.lookup(jndiName); // line 1 cf = (ConnectionFactory) o; // line 2 ConnectionFactory is an interface, defined as: public interface ConnectionFactory extends java.io.Serializable, javax.resource.Referenceable { ... } What happens is: If the jar containing the interface class is on the system classpath, line 2 is executed fine If the

ObjectInputStream custom classloader deserialization issue: resolveClass() not called

二次信任 提交于 2019-12-12 12:26:27
问题 I have an ObjectInputStream and want to load classes with a custom ClassLoader . Thus is created a subclass of ObjectInputStream that overrides the resolveClass() function. Now my problem is that i want to change the ClassLoader during execution. But sometimes resolveClass() does not seem to be executed when I do readObject() on this stream. Then the class is loaded with the wrong ClassLoader . Any idea why resolveClass() is not executed and how to solve this issue? 回答1: resolveClass() will

Different classloaders cause ClassCastException when persisting data via Spring

回眸只為那壹抹淺笑 提交于 2019-12-12 12:08:28
问题 I'm creating an MVC Spring webapp. Using: Jetty (servlet container), DataNucleus (dao platform), DB4O (embedded datastore). When I persist an object (done from within a Spring Controller) using JDO from DataNucleus, it stores to the DB fine. @PersistenceCapable public class Test { @Persistent private String testString; //getter-setters implemented } When I do a simple query for the objects I previously added I get a ClassCastException on my Test class (can't cast a.b.c.Test to a.b.c.Test ).

How can I isolate my Jenkins pipeline Groovy shared library classloader?

北城余情 提交于 2019-12-12 10:36:27
问题 I have a Groovy library made available as a Global shared library: package com.example @Grab(group="org.apache.httpcomponents", module="httpclient", version="[4.5.3,)") import org.apache.http.HttpHost import org.apache.http.impl.client.HttpClients class MyClass implements Serializable { static def run() { return HttpClients.custom() .setProxy(new HttpHost("proxy.example.com", 3128)) .build() } static def debug() { return (""" this: ${this.classLoader.class.toString()} ${this.classLoader

How to send a Class over the wire

北战南征 提交于 2019-12-12 10:00:05
问题 I have the following problem: I want to send a type (java.lang.Class) over the wire and 'define' the class on the other side. I tried like that: ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(MyClass.class); and on the receiving end: ByteArrayInputStream bis = new ByteArrayInputStream(request.getBytes()); ObjectInputStream ois = new ObjectInputStream(bis); Class c = (Class) ois.readObject(); //

Is Java Classloader Delegation model mandatory?

主宰稳场 提交于 2019-12-12 08:58:39
问题 If i have a custom classloader which, instead of delegating to its parent first, tries a search and load of the class itself will it be a violation of some stated/unstated rule? 回答1: The Tomcat webapp classloader follows this model, so I imagine it works to at least some extent :) From the Tomcat classloader documentation: As mentioned above, the web application class loader diverges from the default Java 2 delegation model (in accordance with the recommendations in the Servlet Specification,