urlclassloader

How to load all the jars from a directory dynamically?

为君一笑 提交于 2019-12-06 14:29:25
Hi I am creating a plugin which requires loading jars dynamically and accessing the classes and methods of these jars. I tried using URLClassLoader and am able to load the classes as shown below URL myJarFile = new URL("jar","","file:"+jarPath); URLClassLoader sysLoader =(URLClassLoader)ClassLoader.getSystemClassLoader(); Class sysClass = URLClassLoader.class; Method sysMethod = sysClass.getDeclaredMethod("addURL", new Class[]{URL.class}); sysMethod.setAccessible(true); sysMethod.invoke(sysLoader, new Object[]{myJarFile}); But the issue with this is that we have to load classes into

Detect Java JAR/Code Tampering

ε祈祈猫儿з 提交于 2019-12-06 13:32:29
I'm writing a piece of software that is distributed as a JAR file. Currently, this JAR file can be tampered with to retrieve and save another file that our server transmits via URLClassLoader , be decompiled, and find various things in our code that should remain private for the security of the clients using it. Basically, I want to implement a way to check if the original JAR is tampered with. I know this is paradoxically impossible by implementing a check for validity of a SignedObject in the original class due to the nature of Java being able to be decompiled, but is there some other way

ClassLoader,Thread.currentThread().setContextClassLoader,tomcat的ClassLoader

坚强是说给别人听的谎言 提交于 2019-12-06 06:57:08
ClassLoader,Thread.currentThread().setContextClassLoader,tomcat的ClassLoader 2014-05-07 21:41 Loull 阅读( 6776) 评论( 0) 编辑 收藏 实际上,在Java应用中所有程序都运行在线程里,如果在程序中没有手工设置过ClassLoader,对于一般的java类如下两种方法获得的ClassLoader通常都是同一个 this.getClass.getClassLoader(); Thread.currentThread().getContextClassLoader(); 方法一得到的Classloader是静态的,表明类的载入者是谁; 方法二得到的Classloader是动态的,谁执行(某个线程),就是那个执行者的Classloader。对于单例模式的类,静态类等,载入一次后,这个实例会被很多程序(线程)调用,对于这些类,载入的Classloader和执行线程的Classloader通常都不同。 一、线程上下文类加载器   线程上下文类加载器(context class loader)是从 JDK 1.2 开始引入的。类 java.lang.Thread 中的方法 getContextClassLoader() 和 setContextClassLoader(ClassLoader

Java学习笔记18-类加载机制

十年热恋 提交于 2019-12-06 05:27:31
Java学习笔记18-类加载机制 类生命周期 加载:读取二进制内容 验证:验证class文件格式规范、语义分析、引用验证、字节码验证 准备:分配内存、设置类static修饰的变量初始值 解析:类、接口、字段、类方法等解析 初始化:为静态变量赋值;执行静态代码块 使用:创建实例对象 卸载:从JVM方法区中卸载 类加载器 类加载器负责装入类,搜索网络、jar、zip、文件夹、二进制数据、内存等指定位置的类资源。 一个java程序运行,最少有三个类加载器实例,负责不同类的加载。 Bootstrap loader核心类库加载器:C/C++实现,无对应java类:null;加载JRE_HOME/jre/lib目录,或用户配置的目录;JDK核心类库 rt.jar…String… Extension Class loader:ExtClassLoader的实例:加载JRE_HOME/jre/lib/ext目录,JDK拓展包,或用户配置的目录 application class loader用户应用程序加载器:AppClassLoader的实例:加载java.class.path指定的目录,用户应用程序class-path 或者java命令运行时参数-cp… 验证问题 查看类对应的加载器 通过JDK-API进行查看:java.lang.getClassLoader() 返回装载类的类加载器

Create Classloader with only classes inside specific folder

眉间皱痕 提交于 2019-12-06 00:29:03
I want to load specific jars in ScriptEngineManager using specific ClassLoader This constructor loads the implementations of ScriptEngineFactory visible to the given ClassLoader using the service provider mechanism. The problem when I tried to create Classloader File file = new File("c:\\myclasses\\"); try { // Convert File to a URL URL url = file.toURI().toURL(); // file:/c:/myclasses/ URL[] urls = new URL[]{url}; // Create a new class loader with the directory ClassLoader cl = new URLClassLoader(urls) And I'm getting also class that weren't in class for example Spring Class cls1 = cl

java.lang.NoClassDefFoundError: org/apache/curator/framework/recipes/cache/TreeCacheListener

偶尔善良 提交于 2019-12-05 04:44:56
springboot整合dubbo时候,添加了一下依赖,讲道理,这几个jar包应该是够了的,但是就出现了如下异常, java.lang.NoClassDefFoundError: org/apache/curator/framework/recipes/cache/TreeCacheListener at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_191] at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[na:1.8.0_191] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_191] at java.net.URLClassLoader.defineClass(URLClassLoader.java:468) ~[na:1.8.0_191] at java.net.URLClassLoader.access$100(URLClassLoader.java:74) ~[na:1.8.0_191] at java.net.URLClassLoader$1.run(URLClassLoader.java:369

Dubbo 启动报错 CLassNotFondException

大憨熊 提交于 2019-12-05 04:33:27
java.lang.IllegalStateException: Error processing condition on com.alibaba.boot.dubbo.DubboAutoConfiguration.dubboProtocolConfig at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64) ~[spring-boot-autoconfigure-2.0.3.RELEASE.jar:2.0.3.RELEASE] at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/J

你说的曾经没有我的故事 提交于 2019-12-05 04:16:12
C:\Users\lxn\Desktop\billsystem>java -jar billsystem-0.0.1-SNAPSHOT.jar Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/JarLauncher : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at

Maven运行异常:Exception in thread "main" java.lang.UnsupportedClassVersionError

好久不见. 提交于 2019-12-05 04:10:22
转载请注明来源: http://blog.csdn.net/loongshawn/article/details/50556760 《Java Web工程转换为基于Maven的Web工程》 《Maven Web工程运行异常:Maven.multiModuleProjectDirectory system propery is not set的问题》 《Maven运行异常:Exception in thread “main” java.lang.UnsupportedClassVersionError》 1 背景 Linux平台部署maven项目,提示如下异常: Exception in thread “main”java.lang.UnsupportedClassVersionError: com/autonavi/App : Unsupported major.minor version 51.0 2 异常 异常摘要 Exception in thread "main" java.lang.UnsupportedClassVersionError: com/autonavi/App : Unsupported major.minor version 51.0 详细异常 $sudo ./appctl.sh start /home/admin/rus-api-services

URLClassLoader loads Annotation as com.sun.$Proxy$27

て烟熏妆下的殇ゞ 提交于 2019-12-03 21:14:08
问题 I'm trying to dynamically load a java class. The basic idea is, that a jar contains modules which get loaded dynamically at runtime. This is how I do it (I know it's hacky, but there is no other method to dynamically add a jar to an already existing classloader afaik): Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); method.invoke(moduleLoader, new Object[] { file.toURI().toURL() }); Class fooClass = moduleLoader