classloader

Capitalization and NoClassDefFoundError vs ClassNotFoundException

只愿长相守 提交于 2019-12-05 09:31:05
I'm seeing differences across platforms about when Class.forName() throws ClassNotFoundException and when it throws NoClassDefFoundError. Is this behavior well-defined somewhere, or have I stumbled across a bug? Consider the following code (which is a standalone java file in the default package): public class DLExceptionType { private static void printFindError(String name) { System.out.print(name + ": "); try { Class.forName(name); System.out.println("** no error **"); } catch (Throwable e) { System.out.println(e); } } public static void main(String[] args) { printFindError("DLExceptionType")

WAS 8.5: java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl incompatible with javax.xml.parsers.SAXParserFactory

眉间皱痕 提交于 2019-12-05 08:21:42
I am deploying a J2EE web application in Websphere Application Server 8.5. The web application has a shared library with all the third party libraries. All the internally coded libraries are inside the WEB-INF/lib folder. The problem is that in only some jsps WAS it is throwing the following exception. I think it is related with xercesImpl-2.8.1.jar but I don't understand why it is throwing this exception and why it is throwing in only some pages. In tomcat it is working perfectly. java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl incompatible with javax.xml.parsers

Why ContextClassLoader returns path with exclamation character?

送分小仙女□ 提交于 2019-12-05 07:49:53
I try to open file in jar in WEB-INF/lib with Thread.currentThread().getContextClassLoader(); URL url=classLoader.getResource(myconfig); In debugger I can see: jar:file:/C:/apache-tomcat/webapps/mywebapp/WEB-INF/lib/myjarresource.jar! /conf/configuration.xml Why in file path is "!" ? I think for this reason application cannot open this file. How to receive correct path? Thanks. It means whatever comes after the ! is inside the JAR file. In case of myjarresource.jar!/conf/configuration.xml , open up myjarresource.jar using a compression utility such as 7-zip and you will see that it contains

Resolving the root of a webapp from getResource

不羁岁月 提交于 2019-12-05 07:48:12
问题 I have a file structure like this in my webapp: webapp/ ├── META-INF └── WEB-INF ├── reports │ └── info.txt └── web.xml 3 directories, 2 files I need to get /WEB-INF/reports/info.txt from a class like so: this.getClass().getResource("/WEB-INF/reports/info.txt"); Will this resolve? I'm going to test it, but I'm not sure how Tomcat's classloader resolves things. If this doesn't work, how can I get the file? 回答1: Well, first of all, this.getClass().getResource should not work (though I didn't

What happens when you have the same class twice in a war deployed in tomcat?

∥☆過路亽.° 提交于 2019-12-05 07:41:39
What happens when you have the same compiled class twice in a war deployed in tomcat? (I know it's not a good practice and so on, but what happens behind the scene?) Are there chances of nasty side-effects? I would expect the behaviour is the same as anywhere else you have that situation. The first class found by the class loader will be used, the other will be ignored. If you have one class is in WEB-INF/classes and the other in a jar, the one in WEB-INF/classes will have priority. If the two classes are in a jar, then one of them will be taken and the other ignored. The one that gets chosen

WebappClassLoader memory leak even with no gc roots

我们两清 提交于 2019-12-05 07:30:04
HERE IS THE HEAD DUMP (UPDATED ON 10/29/2013) I'm working in a webapp with: Tomcat 7.0.24 Java 6 Spring 3 (with aop - cglib) SLF4J over Log4j Oracle Coherence After a lot of work, I managed to remove all the strong reference to the class loader and now it is a candidate for the garbage collector. So, memory leak solved? Of course not! Because after several hot deployments a OOME appears due to PermGen space. Thanks to Yourkit, I was able to check that the WebappClassLoader was Pending Finalization which means that is waiting in the finalizer queue (actually, is not the WebappClassLoader itself

URLClassLoader.getResources(“”) (empty resource name) not giving roots of jars

时光怂恿深爱的人放手 提交于 2019-12-05 07:29:54
Consider a URLClassLoader parameterized with a collection of URL s which is a mix of expanded directories and jar files. For example: URL[] urls = new URL[] { new URL("file:/D:/work/temp/jars/spring-security-core-3.2.0.RELEASE.jar"), new URL("file:/D:/work/temp/jars/spring-security-config-3.2.0.RELEASE.jar"), ... new URL("file:/D:/work/temp/domain/bin/"), new URL("file:/D:/work/temp/web/bin/"), ... } URLClassLoader cl = new URLClassLoader(urls); The classloader correctly handles getResources() requests for resources located somewhere inside a package like "org/my/package/conf.properties" . By

Where does bytecode injection happen?

為{幸葍}努か 提交于 2019-12-05 04:43:14
问题 Motivation I have a SomeObject.java file: class SomeObject { String name; } Compiling it creates a bytecode-containing SomeObject.class file. 0xCAFEBABE... If we use SomeObject on the JVM, it is loaded by the current classloader and all works fine. Now let's assume that I'd like to have some dynamic code generation. I can write my custom annotation @Target(ElementType.TYPE) public @interface Data { ... } and add it as a modifier to the class declaration: @Data class SomeObject { String name;

manage conflict on java classpath

百般思念 提交于 2019-12-05 04:27:06
I expose my context : I have two Java programs that run on a unique Weblogic Server : program A and program B. These ones are launched by two ksh : programA.ksh and programB.ksh Both need C.jar but in different versions (but with exactly the same package and classes) : program A need C-1.0.jar program B need C-2.0.jar I precise that both programs share the same weblogic classpath. So, my classpath contains in that order : ..... C-1.0.jar C-2.0.jar ..... How can I do so that each program finds its good library ? For instance, with my actual configuration, program B will always use C-1.0.jar

Issue while loading a dll library file… java.lang.UnsatisfiedLinkError: Can't load library

偶尔善良 提交于 2019-12-05 04:05:41
While loading a dll file, I am getting the following exception: Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\Transliteration\rlpnc-3.1.0-sdk-ia32-w32-msvc80\rlp\bin\ia32-w32-msvc80\btrntjni.dll: The system cannot find message text for message number 0x%1 in the message file for %2 at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(Unknown Source) at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.load0(Unknown Source) at java.lang.System.load(Unknown Source) at com.basistech.util.internal.Native.loadLibrary