classloader

Why does a class containing a method call to a missing Interface within unused code cause a Java class loading error?

痞子三分冷 提交于 2019-12-08 15:55:29
问题 I'm seeing some class loading behavior that appears to be inconsistent with the JVM spec and am wondering if this is a bug. Or if not, hoping someone can explain why. The example code found below simply prints hello from its main method. It has an unused method that contains a method call to a method that declares it takes a 'C' (which is an interface) as an argument. When the main is executed (without A, B, and C in the class path) a ClassNotFound Error is thrown for Interface C. (Note C is

dynamically load implementation of interface in Java

可紊 提交于 2019-12-08 12:37:05
问题 I'm looking for functionality in Java similar to the .NET Managed Extensibility Framework (http://mef.codeplex.com/). For those who don't know MEF, I want something like this: Given an interface public interface IFoo { ... } Dynamically load an implementation of an interface by looking in loaded jars. IFoo foo = loadClassThatImplementsInterface<IFoo>(); The point is that the programmer does not know the name of the implementation at code time, but provides in code an extentsion point. Is this

Map Entities loaded dynamically from external jars or outside classpath

依然范特西╮ 提交于 2019-12-08 11:28:10
问题 I need to map Entities that are not listed at hibernate.cfg.xml, those classes are loaded dynamically from an arbitraty folder. I'm trying to register a ClassLoaderService to change the loading behavior, the following code runs fine if the classes are defined at compile time and exist in the classpath, but if I try to map a dinamically loaded class I get ClassNotFoundException. There are some questions about the same issue, but I didn't find any working solution. URL file = ConsultaBase.class

How can I make a loaded jar use resources from itself rather than its loader?

﹥>﹥吖頭↗ 提交于 2019-12-08 09:19:48
问题 Summary: When I load and run one jar from another jar and that loaded jar attempts to access its resources inside itself, it is unable to find those resources. I believe this is because it is looking inside the jar that loaded it instead of itself. How can I fix this? The problem in more detail: I am attempting to programmatically load a jar file -- let's call it "Server" -- into the Java Virtual Machine through my own Java program -- let's call it "ServerAPI" -- and use extension and some

Can a java classloader load a class more than once

六月ゝ 毕业季﹏ 提交于 2019-12-08 09:01:52
问题 Can a java classloader load a class more than once, ie load new versions of a class, without throwing a LinkageError of "duplicate class definition"? In other words, if we need to dynamically reload a class, can this be done with the same classloader, or does the classloader have to be destroyed first and a new one be created that will load the new version of the class? 回答1: A classloader can only actually load a class once! That means that it can only define it once. It can load it many

Replace classpath of a running Groovy Script (Jenkins Pipeline script)

耗尽温柔 提交于 2019-12-08 08:43:28
问题 In Jenkins Pipeline we have a CpsGroovyScript executed by CPSGroovyShell with a custom classpath which is appended with path to Global Library location. In order to be able to test my changes before making them available for all the Pipelines on my Jenkins instance I want to override classpath by unloading the classes and modifying the script's classpath from itself in runtime. My idea is to prepend current classpath with a new location so that changed classes found first. this.class

Java loading resources Class.class.getResource vs <classname>.class.getResource

你说的曾经没有我的故事 提交于 2019-12-08 07:46:55
问题 What is the difference between the two ? my resource files are packaged in the root level package. And calling Class.class.getResource("/rec.txt") seemed to work in the specific case I tested. But, when I tried to use this jar as a dependency in a larger environment ( hadoop ) this didnt work ( returned null ). But, changing "Class" to any specific class in the code fixed it. Could someone throw some light. 回答1: The reason this is happening is that the way getResource works. It essentially

How to set the orders of jars in Weblogic EAR?

夙愿已清 提交于 2019-12-08 07:17:22
问题 I have an EAR file that contains two different jars that share some classes with an identical package+class name. This results in importance of classloading inside the EAR file itself. How can I tell Weblogic to load one jar from APP-INF/lib before loading a different one in the same APP-INF/lib? I need to define a specific order to that if there is a conflict, it will take from JAR a and not JAR b. I'm using Webogic 11g (10.3). Thanks. 回答1: The top-level element in weblogic-application.xml

How do I resolve this Weblogic intermittent java.lang.LinkageError? What are the steps to understanding what it means and fix it?

不问归期 提交于 2019-12-08 06:56:52
问题 I have an intermittent linkage error thrown: (That's basically all the information I have) java.lang.LinkageError loader constraint violation: when resolving field 'service' of the class loader instance of java/net/FactoryURLClassLoader) of the referring class org/apache/axis/client/Stub, and the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) for the field's resolved type, java/xml/rpc/Service, have different class objects for that type Or in a more readable way

JBoss 4.2 startup throws NoClassDefFoundError

本小妞迷上赌 提交于 2019-12-08 06:45:59
问题 I am having trouble starting a JBoss 4.2.2 server - it is producing the following error message (from org.jboss.kernel.plugins.dependency.AbstractKernelController ) : Error installing to Described: name=WSDeployerHook_JAXWS_EJB3 state=Not Installed mode=Manual requiredState=Create java.lang.NoClassDefFoundError: org/jboss/ejb3/interceptors/direct/IndirectContainer Looking through the JBoss source code, I have turned on TRACE level logging for certain classes, though all it is telling me is