classloader

Order of class loading from a .war file

放肆的年华 提交于 2019-12-17 18:37:45
问题 I've got a question regarding the guarantees, if any, in the following scenario (note that the question is not "How to do this in a different way?" , the question is really about class loading order in the following case (to better understand how class loading works). Here's the hypothetical scenario... There's a .war file that has the following (partial) directory structure: WEB-INF/classes/com/acme/Bunny.class . . . WEB-INF/lib/acme.jar Both Bunny.class files have import referencing other

compiling and running user code with JavaCompiler and ClassLoader

纵饮孤独 提交于 2019-12-17 18:33:46
问题 I am writing web app for java learning. Using which users may compile their code on my serwer + run that code. Compiling is easy with JavaCompiler: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, prepareFile(nazwa, content)); task.call(); List<String> returnErrors = new ArrayList<String>(); String tmp = new

How to put custom ClassLoader to use?

夙愿已清 提交于 2019-12-17 18:15:46
问题 Hello all and thanks for the attention! I have a problem that must both be easy and obvious, yet I am stuck. I want to deliver dynamically created Java classes to be used by a 3rd party library via a custom ClassLoader. Now my problem is: How do I set my custom ClassLoader to be used to load this classes when I do not load them directly myself? I thought when I used my ClassLoader to load a certain class, it became this class's ClassLoader, and all classes loaded from that class would be

Do I have a JAXB classloader leak

只谈情不闲聊 提交于 2019-12-17 16:49:05
问题 I have an application deployed on Glassfish. Over time the number of loaded classes climbs into the millions and my permgen seems to rise. To help troubleshoot I added the following to my jvm arguments. -XX:+PrintGCDetails -XX:+TraceClassUnloading -XX:+TraceClassLoading Now when watching the output, I see the same classes being loaded over and over again. Basically every time a web service is called and JAXB is used to process the xml. [Loaded com.strikeiron.ZIPCodesInRadius$JaxbAccessorF

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

僤鯓⒐⒋嵵緔 提交于 2019-12-17 16:17:10
问题 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! 回答1: You can set the system

Loading files with ClassLoader

两盒软妹~` 提交于 2019-12-17 16:15:03
问题 This problem has been bugging me for a while. I have to load a couple files in my java app, and the only way I got working so far looks like this: URL hsURL; if(System.getProperty("os.name").toLowerCase().contains("windows")) { hsURL = new URL("file:/" + System.getProperty("user.dir") + "/helpsets/helpset.hs"); } else { hsURL = new URL("file://" + System.getProperty("user.dir") + "/helpsets/helpset.hs"); } But this is ugly and terrible. For a while I thought I had this working: hsURL =

What purpose does Class.forName() serve if you don't use the return value?

こ雲淡風輕ζ 提交于 2019-12-17 15:43:25
问题 I've seen this line in a sample application for using a commercial JDBC driver: Class.forName("name.of.a.jcdb.driver") The return value is not used. What purpose does this line serve? 回答1: It performs a static loading of that class. So anything in the static { } block, will run. 回答2: Maybe some code snippet will help. This is from Sun's JDBC-ODBC bridge driver, //-------------------------------------------------------------------- // Static method to be executed when the class is loaded. //--

Updating a JAR whilst running

我的未来我决定 提交于 2019-12-17 15:38:55
问题 Given a jar runs within a JVM would it be possible to unload the current running Jar and remove it from the system. Download a new version and rename it with the same name of the last Jar and then initialise the new Jar, creating a seamless update of the Jar within the JVM. Is it even possible to instruct the JVM to perform this action? Is it even possible to update a Jar whilst its running? 回答1: Download a new version and rename it with the same name of the last Jar and then initialise the

Where on the file system was my Java class loaded from?

前提是你 提交于 2019-12-17 15:36:31
问题 I think this is a situation every Java programmer runs into if they do it long enough. You're doing some debugging and make a change to class. When you go to re-run the program, these changes don't seem to be picked up but rather the old class still seems to be running. You clean and rebuild everything, same issue. Sometimes, this can come down to a classpath issue, of the same class being on the classpath more than once, but there doesn't seem to be an easy way to figure out where the class

ClassLoader getResourceAsStream returns null

こ雲淡風輕ζ 提交于 2019-12-17 10:57:14
问题 My project directory structure (in Eclipse): MyProject/ src/ --> "source directory" on Eclipse's classpath/buildpath com.me.myapp Driver myconfig.txt In Driver , I have the following code: public class Driver { public static void main(String[] args) { InputStream is = ClassLoader.getSystemClassLoader.getResourceAsStream("myconfig.txt"); if(is == null) System.out.println("input stream is null"); else System.out.println("input stream is NOT null :-)"); } } When I run this I get the following