classloader

When does the JVM load classes?

▼魔方 西西 提交于 2019-11-28 05:57:26
Assume I have the following class: class Caller { public void createSomething() { new Something(); } } Would executing this line: static void main() { Class<?> clazz = Caller.class; } cause the JVM to load the class Something or is the class loading deferred until the method createSomething() is called? A class is loaded only when you require information about that class. public class SomethingCaller { public static Something something = null; // (1) does not cause class loading public static Class<?> somethingClass = Something.class; // (2) causes class loading public void doSomething() { new

Struts2 + Classloader Vulnerability + How to reproduce

送分小仙女□ 提交于 2019-11-28 05:31:44
问题 How to reproduce the security issue CVE-2014-0094. I googled but couldn't able to find any reference to the same. 回答1: Got it working. I have to enable logging (for ognl package) to see the error. Pass in parameter like class.classLoader.resource.dircontext.docBase=someText to the struts2 application. localhost:8080/sampleApp/showlogin.do?class.classLoader.resource.diretext.docBase=someText Then in the log I would see something like this. java.lang.IllegalArgumentException: Document base base

Classloaders hierarchy in Java 9

こ雲淡風輕ζ 提交于 2019-11-28 05:06:55
As of Java-8, I know the hierarchy of the classloaders has been as follows:- Bootstrap classloader -> Extension classloader -> Application classloader What is the change in the hierarchy of classloaders in Java 9 and how does it works? The ClassLoader as revised in Java-9 states that: The Java run-time has the following built-in class loaders: Bootstrap class loader : The virtual machine's built-in class loader typically represented as null, and does not have a parent. Platform class loader : To allow for upgrading/overriding of modules defined to the platform class loader, and where upgraded

getClass().getResource(“/”) returns null in command line

别等时光非礼了梦想. 提交于 2019-11-28 04:58:31
问题 I'm trying to read a file in my maven project at /src/main/resources/file.txt. I'm using URL url=this.getClass().getResource("/"); String filePath=url.getPath()+"file.txt"; url object gets the correct value when this is run thru eclipse. But, when I package the jar and run it in command line: jar -cp myjar.jar SampleTest It returns null for 'url' object and throws a NullPointerException in the next line. I have openend my Jar file using file browser and checked. It has the 'file.txt' in "/"

Android: “Class loader may fail for processes that host multiple applications”

拈花ヽ惹草 提交于 2019-11-28 04:33:37
What does this message in Eclipse's logcat for Android mean? W/ActivityThread: ClassLoader.getResources: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader()); Unfortunately, there is no context given as to this warning, so I don't know what causes this problem and how I can resolve it. Background information The message means that Android has setup a dummy ClassLoader with Thread.currentThread()

Why is custom system classloader not working?

删除回忆录丶 提交于 2019-11-28 04:27:50
问题 I'm trying to override the system's class loader using using the flag -Djava.system.class.loader=MyLoader . However, MyLoader is still not being used when classes are loaded. MyLoader 's code: public class MyLoader extends ClassLoader { public MyLoader(ClassLoader parent) { super(S(parent)); } private static ClassLoader S(ClassLoader cl) { System.out.println("---MyLoader--- inside #constructor(" + cl + ")..."); return cl; } @Override public Class<?> loadClass(String name, boolean resolve)

JasperReports: How to add font not in the application classpath

戏子无情 提交于 2019-11-28 04:06:57
问题 I am trying to use a font, that is not installed on my local OS, with a JasperReports . The jasper report uses in this way: <textField> <reportElement x="0" y="0" width="137" height="20"/> <textElement> <font fontName="Corbel" size="12"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{something}]]></textFieldExpression> </textField> The font named Corbel was exported as a font extension (using iReport) and is contained in file (Corbel.jar), in folder, on my system. I

getResourceAsStream fails under new environment?

☆樱花仙子☆ 提交于 2019-11-28 03:54:31
问题 Hallo, i have following line of code: InputStream passoloExportFileInputStream = getClass().getClassLoader().getResourceAsStream("/com/thinkplexx/lang/de/general.xml"); and i know that jar with com/thinkplexx/lang/de/general.xml is in classpath. It worked under "previous environment", which is maven2 build. Now, i evaluate maven3 and it doesn't work! I know, that if i change the code to be: InputStream passoloExportFileInputStream = getClass().getClassLoader().getResourceAsStream("com

How to get classpath from classloader?

徘徊边缘 提交于 2019-11-28 03:39:32
I am using some third party code which when given a '-classpath' command line argument doesnt set the java.class.path, but instead just creates a classloader, adds all the urls for the items on the command line specified classpath to the classloader, and then sets it to be the context classloader. In a plugin class to this code that I have written, I get an instance of this classloader, and somehow need to use it to get back the underlying classpath, so that I can use it in an invocation of JavaCompiler.getTask(...) and compile some other code on the fly. However there doesn't seem to be

How does class loading work when the same class exists in different applications on the same server?

一个人想着一个人 提交于 2019-11-28 03:09:10
I have multiple web-apps running on an app server and each web-app WAR file contains a copy of the same jar file. Does this mean that a class in that jar file will be loaded multiple times in the JVM, once for each WAR file it exists in? Following on from that, if I have a static synchronized method in such a class, is it only synchronized among threads within the web-app it exists in but not synchronized against the same method in the same class in a different jar file in a different WAR file? (Hope the question makes sense, will clarify if necessary). If this is the case I presume the best