classloader

Running a compiled java .class file from within java code and capturing output

荒凉一梦 提交于 2021-02-11 08:36:54
问题 I'm trying to write a java program with an interface that allows the user to create .java file and compile and run it (essentially a very simplistic IDE). I'm using java swing for the gui and have so far been able to compile a .java file from within the interface into a .class file. I've been researching how to run a .class file from within java code but have found a wide range of answers which I haven't been able to get working. Here is the relevant code for compilation: File javaFile = new

Running a compiled java .class file from within java code and capturing output

 ̄綄美尐妖づ 提交于 2021-02-11 08:36:13
问题 I'm trying to write a java program with an interface that allows the user to create .java file and compile and run it (essentially a very simplistic IDE). I'm using java swing for the gui and have so far been able to compile a .java file from within the interface into a .class file. I've been researching how to run a .class file from within java code but have found a wide range of answers which I haven't been able to get working. Here is the relevant code for compilation: File javaFile = new

get CtClass using specific ClassLoader

ぐ巨炮叔叔 提交于 2021-02-10 18:44:44
问题 I have a class structure like this: package com.mydomain.myproject; public class Outer{ public class Inner{ //some code } } Now, I can get a CtClass of the inner class using: ClassPool pool=ClassPool.getDefault(); CtClass innerCt=pool.getCtClass("com.mydomain.myproject.Outer$Inner"); The problem occurs if those classes are loaded by a special ClassLoader . ClassPool#getCtClass fails because the ClassLoader it uses doesn't know of the class. I get the following exception: javassist

get CtClass using specific ClassLoader

纵饮孤独 提交于 2021-02-10 18:41:10
问题 I have a class structure like this: package com.mydomain.myproject; public class Outer{ public class Inner{ //some code } } Now, I can get a CtClass of the inner class using: ClassPool pool=ClassPool.getDefault(); CtClass innerCt=pool.getCtClass("com.mydomain.myproject.Outer$Inner"); The problem occurs if those classes are loaded by a special ClassLoader . ClassPool#getCtClass fails because the ClassLoader it uses doesn't know of the class. I get the following exception: javassist

Spring IllegalAccessException after isolating a module in a separate ClassLoader

早过忘川 提交于 2021-02-10 17:15:02
问题 I have had a problem involving jar clash between incompatible versions of BouncyCastle. We have solved it by creating a bean that, using a Spring-defined ClassLoader bean injected as property, invokes services from classes not stored in official WEB-INF/lib folder. Following are the beans definitions <bean id="metainfJarClassloader" class="com.jdotsoft.jarloader.JarClassLoaderFactory" factory-method="create"/> <bean id="jadesFactory" class="it.csttech.proxy.jades.JadesFactory"> <constructor

Spring IllegalAccessException after isolating a module in a separate ClassLoader

好久不见. 提交于 2021-02-10 17:13:42
问题 I have had a problem involving jar clash between incompatible versions of BouncyCastle. We have solved it by creating a bean that, using a Spring-defined ClassLoader bean injected as property, invokes services from classes not stored in official WEB-INF/lib folder. Following are the beans definitions <bean id="metainfJarClassloader" class="com.jdotsoft.jarloader.JarClassLoaderFactory" factory-method="create"/> <bean id="jadesFactory" class="it.csttech.proxy.jades.JadesFactory"> <constructor

How to load java.util.TimeZone more then once in JVM

◇◆丶佛笑我妖孽 提交于 2021-02-10 13:33:47
问题 I create my custom class loader : new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); where urls is a new Url("java.util.TimeZone") After that I load class by name : Class<?> newTimeZoneClass = loader.loadClass("java.util.TimeZone"); and newTimeZoneClass==TimeZone.class returns true . The main reason of that my class loader load class from parent loader. How to fix it? 回答1: You cannot do this. The Java security model prevents any class loader creating a class in the

Why would Java classloading fail on Linux, but succeed on Windows?

柔情痞子 提交于 2021-02-10 05:17:23
问题 I've got a Java web application (using Spring), deployed with Jetty. If I try to run it on a Windows machine everything works as expected, but if I try to run the same code on my Linux machine, it fails like this: [normal startup output] 11:16:39.657 INFO [main] org.mortbay.jetty.servlet.ServletHandler$Context.log>(ServletHandler.java:1145) >16> Set web app root system property: 'webapp.root' = [/path/to/working/dir] java.lang.reflect.InvocationTargetException at sun.reflect

Why would Java classloading fail on Linux, but succeed on Windows?

一笑奈何 提交于 2021-02-10 05:16:08
问题 I've got a Java web application (using Spring), deployed with Jetty. If I try to run it on a Windows machine everything works as expected, but if I try to run the same code on my Linux machine, it fails like this: [normal startup output] 11:16:39.657 INFO [main] org.mortbay.jetty.servlet.ServletHandler$Context.log>(ServletHandler.java:1145) >16> Set web app root system property: 'webapp.root' = [/path/to/working/dir] java.lang.reflect.InvocationTargetException at sun.reflect

Java - Singleton usage with multiple class loaders

让人想犯罪 __ 提交于 2021-02-09 10:32:34
问题 I have a simple singleton class in Java that looks like the following one: public class Singleton{ private static Singleton instance; private Singleton(){} public static Singleton getInstance(){ if (instance == null){ instance = new Singleton(); } return instance; } public void doSomething(){ ... } } My code also contains two classes, from now on called A and B, that both have the following structure: public class Foo{ ... public void bar(){ ... Singleton.getInstance().doSomething(); ... } ..