classloader

What does JVM flag CMSClassUnloadingEnabled actually do?

天涯浪子 提交于 2019-11-26 02:05:26
问题 I cannot for the life of me find a definition of what the Java VM flag CMSClassUnloadingEnabled actually does, other than some very fuzzy high-level definitions such as \"gets rid of your PermGen problems\" (which it doesn\'t, btw). I have looked on Sun\'s/Oracle\'s site, and even the options list doesn\'t actually say what it does. Based upon the name of the flag, I\'m guessing that the CMS Garbage Collector doesn\'t by default unload classes, and this flag turns it on - but I can\'t be sure

Java resource as file

落花浮王杯 提交于 2019-11-26 01:29:48
问题 Is there a way in Java to construct a File instance on a resource retrieved from a jar through the classloader? My application uses some files from the jar (default) or from a filesystem directory specified at runtime (user input). I\'m looking for a consistent way of a) loading these files as a stream b) listing the files in the user-defined directory or the directory in the jar respectively Edit: Apparently, the ideal approach would be to stay away from java.io.File altogether. Is there a

Difference between thread's context class loader and normal classloader

泄露秘密 提交于 2019-11-26 01:29:24
问题 What is the difference between a thread\'s context class loader and a normal class loader? That is, if Thread.currentThread().getContextClassLoader() and getClass().getClassLoader() return different class loader objects, which one will be used? 回答1: Each class will use its own classloader to load other classes. So if ClassA.class references ClassB.class then ClassB needs to be on the classpath of the classloader of ClassA , or its parents. The thread context classloader is the current

Is it possible to dynamically load a library at runtime from an Android application?

ぃ、小莉子 提交于 2019-11-26 00:57:24
问题 Is there any way to make an Android application to download and use a Java library at runtime? Here is an example: Imagine that the application needs to make some calculations depending on the input values. The application asks for these input values and then checks if the required Classe s or Method s are available. If not, it connects to a server, downloads the needed library, and loads it at runtime to calls the required methods using reflection techniques. The implementation could change

URL to load resources from the classpath in Java

烈酒焚心 提交于 2019-11-26 00:39:11
问题 In Java, you can load all kinds of resources using the same API but with different URL protocols: file:///tmp.txt http://127.0.0.1:8080/a.properties jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class This nicely decouples the actual loading of the resource from the application that needs the resource, and since a URL is just a String, resource loading is also very easily configurable. Is there a protocol to load resources using the current classloader? This is similar to the Jar protocol,

How to load a jar file at runtime [duplicate]

浪子不回头ぞ 提交于 2019-11-26 00:15:27
问题 This question already has an answer here: How should I load Jars dynamically at runtime? 15 answers I was asked to build a java system that will have the ability to load new code (expansions) while running. How do I re-load a jar file while my code is running? or how do I load a new jar? Obviously, since constant up-time is important, I\'d like to add the ability to re-load existing classes while at it (if it does not complicate things too much). What are the things I should look out for?

Java, Classpath, Classloading => Multiple Versions of the same jar/project

时间秒杀一切 提交于 2019-11-25 23:46:34
问题 I know this may be a silly question for experienced coders. But I have a library (an http client) that some of the other frameworks/jars used in my project require. But all of them require different major versions like: httpclient-v1.jar => Required by cralwer.jar httpclient-v2.jar => Required by restapi.jar httpclient-v3.jar => required by foobar.jar Is the classloader intelligent enough to seperate them somehow? Most likely not? How does the Classloader handle this, in case a Class is the

Find where java class is loaded from

无人久伴 提交于 2019-11-25 23:17:43
问题 Does anyone know how to programmaticly find out where the java classloader actually loads the class from? I often work on large projects where the classpath gets very long and manual searching is not really an option. I recently had a problem where the classloader was loading an incorrect version of a class because it was on the classpath in two different places. So how can I get the classloader to tell me where on disk the actual class file is coming from? Edit: What about if the classloader

What is the difference between Class.getResource() and ClassLoader.getResource()?

孤街浪徒 提交于 2019-11-25 22:34:12
问题 I wonder what the difference is between Class.getResource() and ClassLoader.getResource() ? edit: I especially want to know if any caching is involved on file/directory level. As in \"are directory listings cached in the Class version?\" AFAIK the following should essentially do the same, but they are not: getClass().getResource() getClass().getClassLoader().getResource() I discovered this when fiddling with some report generation code that creates a new file in WEB-INF/classes/ from an

Scanning Java annotations at runtime

試著忘記壹切 提交于 2019-11-25 22:28:20
问题 What is the best way of searching the whole classpath for an annotated class? I\'m doing a library and I want to allow the users to annotate their classes, so when the Web application starts I need to scan the whole classpath for certain annotation. Do you know a library or a Java facility to do this? Edit: I\'m thinking about something like the new functionality for Java EE 5 Web Services or EJB\'s. You annotate your class with @WebService or @EJB and the system finds these classes while