classloader

java.lang.LinkageError: ClassCastException

北慕城南 提交于 2019-11-28 03:02:10
问题 I do experience a really annoying problem with TestNG and RESTeasy. I do have a class that runs several tests against an API class which uses the RESTeasy framework to expose itself. However if I let the test run with maven (mvn test), then I get the following exception: java.lang.LinkageError: ClassCastException: attempting to castjar:file:/C:/Users/rit/.m2/repository/org/jboss/resteasy/jaxrs-api/2.3.0.GA/jaxrs-api-2.3.0.GA.jar!/javax/ws/rs/ext/RuntimeDelegate.classtojar:file:/C:/Users/rit/

Get bytecode from loaded class

独自空忆成欢 提交于 2019-11-28 02:52:04
问题 Suppose in my JVM I have a loaded class Class<C> myClass . Is there a reliable way to ask the JVM for the bytecode contents of the .class? I.e. something like this: <C> byte[] getClassBytecode(Class<C> myClass) { return /* the contents of the .class resource where C was loaded from */; } (obviously an InputStream would be as good as the byte[] ). I know I can use myClass.getResource() (and friends) to fetch the class file, but hammering on the class name to get an URL to feed to getResource

How to make the jvm load my java.lang.String instead of the one in rt.jar

可紊 提交于 2019-11-28 01:34:48
问题 I studied java classloader rencently. Now I want to write a class that has the same package name and class name as one of class in rt.jar. For example, write a java.lang.String class by myself, and how to break the parents delegation model to make the jvm load my java.lang.String instead of the one in rt.jar. Re-edit Thx, tried. And ↓↓↓ D:\>java -verbose -Xbootclasspath/p:D:/myrt.jar -jar exe.jar [Opened D:\myrt.jar] [Opened C:\java\jre\lib\rt.jar] [Loaded java.lang.Object from C:\java\jre

XPath class resolution in JBoss5

烈酒焚心 提交于 2019-11-28 00:26:00
问题 I'm having a hard time figuring out where the problem is coming from, so I'm posting this in the hopes that others might have found something similar to this elsewhere and are kind enough to share their insight. I'm using a JBoss 5.0.1.GA application server running on top of a Sun Java 1.6.0-13 JDK . For the WAR file in the generated Web Service, I use a Axis2 1.4 WS engine whose JAR files are inserted by Eclipse Galileo into the project's WEB-INF/lib directory when creating the Webservice

Explanation of how classloader loads static variables

丶灬走出姿态 提交于 2019-11-28 00:04:14
问题 Ok so this is a newbie question on java, but i can't seem to get my head around it. I have the following code inside my class private static final String [] LIST_CODE = gerarListCode(); private static final int [][] LIST_INTEGER = new int [][] { {947,947}, {110,103}, {947,958}, {110,120}, {947,954}, {103,107}, {947,967}, {110,99,104}}; private static String [] gerarListCode() { String [] listCode = new String [LIST_INTEGER.length]; for (int i=0 ; i<LIST_INTEGER.length ; i++) { //do some stuff

Java 9, compatability issue with ClassLoader.getSystemClassLoader

两盒软妹~` 提交于 2019-11-27 23:10:44
The following code adds jar file to the build path, it works fine with Java 8. However, it throws exception with Java 9, the exception is related to the cast to URLClassLoader. Any ideas how this can be solved? an optimal solution will edit it to work with both Java 8 & 9. private static int AddtoBuildPath(File f) { try { URI u = f.toURI(); URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class<URLClassLoader> urlClass = URLClassLoader.class; Method method = urlClass.getDeclaredMethod("addURL", URL.class); method.setAccessible(true); method.invoke

log4j and the thread context classloader

a 夏天 提交于 2019-11-27 22:57:54
I'm a newbie to Java and just starting to figure out the concept of class loaders. Right now I am having some issues with log4j regarding its use of the thread context classloader. I'm getting the following errors: A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable. The class "org.apache.log4j.Appender" was loaded by [java.net.URLClassLoader@105691e] whereas object of type "org.apache.log4j.ConsoleAppender" was loaded by [sun.misc.Launcher$AppClassLoader@16930e2]. Could not instantiate appender named "CONSOLE". My application works roughly

Java EE class loading standard

本秂侑毒 提交于 2019-11-27 22:56:01
WebSphere comes with parent last and parent first. Is this Java EE compliant? Is this supported by all application servers that are Java EE 5 compliant? Aravind R. Yarram I did my own research (going through the specs and few blogs) and below is what I've figured EAR The spec DOES NOT define or mandate how the class loaders should work within an EAR. It however defines that there SHOULD be per thread context class loader for runtime loading of classes there MIGHT be a hierarchical class loading mechanism for resolving classes (app server vendors are free to implement whichever way they choose

getSystemResourceAsStream() returns null

故事扮演 提交于 2019-11-27 22:26:39
Hiii... I want to get the content of properties file into InputStream class object using getSystemResourceAsStream(). I have built the sample code. It works well using main() method,but when i deploy the project and run on the server, properties file path cannot obtained ... so inputstream object store null value. Sample code is here.. public class ReadPropertyFromFile { public static Logger logger = Logger.getLogger(ReadPropertyFromFile.class); public static String readProperty(String fileName, String propertyName) { String value = null; try { //fileName = "api.properties"; //propertyName =

How to set my custom class loader to be the default?

十年热恋 提交于 2019-11-27 22:15:13
I'm trying to practice myself with custom class loaders, and I've some questions. Is there a way to indicate the JVM to use my custom class loader globally? For example, I wrote small app running under Tomcat 6. The servlet is managed by the container, where should I set my class loader? In addition, the webapp uses some 3rd party jars, can I control the classes loading of those jars? Are the answers to the above will be different in case of standalone app? Thanks! You can set the system default class loader as a JVM argument: java -Djava.system.class.loader =com.test.YourCustomClassLoader com