classloader

Replacing java class?

我是研究僧i 提交于 2019-11-29 17:39:54
I'm working on a sandbox feature for my java antivirus, and I've come into a question: Does the specified package on a class matter for compilation? Example: I'm running a program that wants to use Runtime.getRuntime().exec() , when the classloader attempts to load that to run a method, does it check the package qualified in the file, if they exist? I would prefer not to try and change files in the JVM, but to simply load ones from a different package. I can accomplish the loading and such, but my only dilemma, will it crash and burn? Inside the java, it would be registered as say, java.lang

Loading Spring context with specific classloader

自作多情 提交于 2019-11-29 17:26:51
问题 How can I go about loading a Spring context with my own ClassLoader instance? 回答1: Many Spring Context Loader (for example ClassPathXmlApplicationContext ) are subclass of DefaultResourceLoader. DefaultResourceLoader has a constructor where you can specify the Classloader and also has a setClassLoader method. So it is your task to find a constructor of the Spring Context Loader you need, where you can specify the classloader, or just create it, and then use the set to set the classloader you

ClassCastException: MyFilter cannot be cast to javax.servlet.Filter

戏子无情 提交于 2019-11-29 14:35:06
I'm migrating an application to JBoss 7, where all dependencies were in "JBOSS_HOME/server/default/lib" (JBoss 4). I included the lib "servlet.jar" (javax.servlet. *), however, after setting a Global Module for JBoss 7 (modules.xml, standalone.xml, jboss-deployment-structure.xml in war files), libraries are loaded normally by JBoss. When JBoss 7 tries to start the filters, I get following exception: 15:09:15,222 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/RegistrarValorDolar]] (MSC service thread 1-2) Exception starting filter cripto: java.lang.ClassCastException

Load Java-Byte-Code at Runtime

半世苍凉 提交于 2019-11-29 14:13:00
问题 I got some java-byte-code (so compiled java-source) which is generated in my program. Now I want to load this byte-code into the currently running Java-VM and run a specific function. I'm not sure how to accomplish this, I digged a little bit into the Java Classloaders but found no straight way. I found a solution which takes a class-file on the harddisk, but the bytecode I got is in a Byte-Array and I dont want to write it down to the disk but use it directly instead. Thanks! 回答1: you need

How do I use the Java ClassLoader to load a file fromthe classpath?

拟墨画扇 提交于 2019-11-29 14:00:25
问题 I want to use the ClassLoader to load a properties file for the Properties class. I've simplified the below code to remove error handling for the purposes of this discussion: loader = this.getClass().getClassLoader(); in = loader.getResourceAsStream("theta.properties"); result = new Properties(); result.load(in); In the same directory as this class I have the file "theta.properties" but the InputStream is always null. Am I putting the file in the wrong place? I'm using eclipse and its set to

Why is the setContextClassLoader() method placed on Thread?

放肆的年华 提交于 2019-11-29 13:59:13
问题 Why is the setContextClassLoader() method placed on Thread ? What different thread have different classloaders? The question is what if I extended a ClassLoader , loaded there some new classes. to the my custom classloader. Now , I want it to be the context classloader , so I call the method Thread.currentThread().setContextClassLoader(loader) . Are these new classes awailable only in the context of the current thread ? Or how does it work? Thanks 回答1: The Context class loader is the class

scala as scripting language [duplicate]

。_饼干妹妹 提交于 2019-11-29 13:40:16
Possible Duplicate: “eval” in Scala I know scala is a compiled language, but I do also know that I can dynamically load classes into the jvm, and I can call the scala compiler at runtime, last but not least I do also have an awesome repl, so having scala as a scripting language should be possible. so there are some tasks I need to get to run: simple interpret: val src = """ println("Hello World") """ interpret(src) call external functions: object A{ def foo = println("Hello World") } val src = """ A.foo """ interpret(src) implement functionality: trait T{ def foo:String } val src = """ class A

analyze jar file programmatically

北慕城南 提交于 2019-11-29 13:40:01
I need to count the number of compiled classes, interfaces and enums in a given jar file programmatically (so I need three separate numbers). Which API would help me? (I can't use third party libraries.) I've already tried quite tricky scheme which seems not always correct. Namely, I read each ZipEntry into a byte[] and then feed the result to my custom class loader which extends standard CalssLoader and just sends this byte[] to ClassLoader.defineClass (which is protect and couldn't be called from application code directly). Full code is on the Pastebin . A jar file is a zip file with a

Stock JDK classes and the “null” ClassLoader?

走远了吗. 提交于 2019-11-29 13:32:30
Hi guys : Im trying to debug a very strange class error by looking at the ClassLoader s for some dynamically created components. ClassLoader s are something I've never played much with - and im surprised that standard JDK classes have null Class loader instances. Can somebody explain the output of this simple main method in terms of the classes whose loaders I am attempting to print , and also more generally - the way ClassLoader s work on the JVM and how we can debug missing classes using ClassLoader s. public class MyClass { /** * @param args */ public static void main(String[] args) {

CompletableFuture / ForkJoinPool Set Class Loader

做~自己de王妃 提交于 2019-11-29 12:17:09
问题 I tackled down a very specific problem, whose solution seems to be something basic: My (Spring) application's classloader hierarchy is something like this: SystemClassLoader -> PlatformClassLoader -> AppClassLoader If I use Java CompleteableFuture to run threads. the ContextClassLoader of the threads is: SystemClassLoader -> PlatformClassLoader -> ThreadClassLoader Thus, I cannot access any class in AppClassLoader although I have to because all external library classes reside there. The