设为首页 收藏本站
查看: 415|回复: 0

[经验分享] Tomcat配置自己的Classloader

[复制链接]

尚未签到

发表于 2017-1-21 09:49:58 | 显示全部楼层 |阅读模式
Tomcat配置自己的Classloader

http://www.52webpro.cn/archives/view-15079-1.html
http://segmentfault.com/q/1010000000155690
http://bbs.csdn.net/topics/190167594
http://yuan-xulong.iteye.com/blog/1056820
http://space.itpub.net/?uid-23071790-action-viewspace-itemid-702545


Linux操作系统下/etc/hosts文件配置方法
http://space.itpub.net/21639366/viewspace-604530

手动创建Oracle 11g数据库
http://blog.csdn.net/carlwu/article/details/2978130

WebSphere Application Server Community Edition V2.0 中的新特性
http://www.ibm.com/developerworks/cn/websphere/library/techarticles/0709_jain/0709_jain.html?s_cmp=techccid&s_tact=105agx52

http://publib.boulder.ibm.com/wasce/V2.0.0/zh_CN/shutdown.html
http://publib.boulder.ibm.com/wasce/V2.1.0/en/quick-start.html

http://stackoverflow.com/questions/11246598/how-to-make-tomcat-work-with-tomcatinstrumentableclassloader-defined-in-meta-inf

http://www.oschina.net/question/68887_26014
http://swingboat.iteye.com/blog/528022

jar 命令 打包详解
http://boris-song.iteye.com/blog/234822
http://quicker.iteye.com/blog/838323

http://shashankmjain.blogspot.com/2009/08/instrumenting-class-with-custom-tomcat.html

http://zhidao.baidu.com/question/290837823.html

--


Instrumenting a class with custom Tomcat Class loader
I have been experimenting with the idea of runtime instrumentation of java classes for quite some time.
Java 5 provides a mechanism using a java agent to intercept the classloading process but here I am going to look into creating a custom Class loader for Tomcat and changing the class bytes on the fly using the javassist library.

Create a web project using Eclipse or any IDE of your choice.
Create a context.xml file in the META-INF directory of the web app. The content will be similar to


loaderClass="com.test.SampleLoader"
useSystemClassLoaderAsParent="false"
delegate="false"/>



After doing this we need to implement the SampleLoader class
The class should be a subclass of WebappClassLoader from Tomcat. We will override the

protected Class findClassInternal(String name) throws ClassNotFoundException method.
The method can be copied from the Tomcat WebappClassLoader class.
Under the if (entry.loadedClass == null) {
method we will change the byte stream of the class using javassist something like this

byte[] b =entry.binaryContent;
String name1 ="com.sample.Test";
pool.insertClassPath(new ByteArrayClassPath(name1, b));
if(name.equals(name1))
{
CtClass cc = pool.get(name);
cc.getConstructors()[0].insertBefore("{System.out.println(\"Before Instantiaition\");}");
cc.getConstructors()[0].insertAfter("{System.out.println(\"After Instantiation\");}");
System.out.println("After classworking "+cc.toBytecode().length);
entry.binaryContent=cc.toBytecode();
}
The same can be extended to intercept any method call.
The class is defined by the classloader after the byte array stream is modified. So the modified class is loaded into the jvm by the custom classloader.

Also the classes can be loaded from an alternate source rather then the web-inf/lib and classes directory
This can be useful when we want to write interceptors to the method calls or create proxies on the fly.

The Custom classloader can be packaged and the jar needs to be placed in CATALINA_HOME/lib directory alongside the javassist libs..
POSTED BY SHASHANK JAIN AT 5:59 AM
LABELS: BYTE CODE INSTRUMENTATION, CUSTOM TOMCAT CLASSLOADER

--

http://www.sf-express.com/cn/sc/delivery_step/waybill_track/track.html
117326721579


Oracle创建用户、表空间、导入导出、...命令
http://www.cnblogs.com/cloudwalf/archive/2008/09/04/1284033.html

读取目录及子目录下指定文件名的路径
http://amulin.iteye.com/blog/1643202
http://blog.csdn.net/chfzhb/article/details/2859973


在tomcat中如何装载加密后的class文件  
http://blog.163.com/tim_plenty/blog/static/567106462007316113420/

利用自定义Classloader保护加密class文件的方式,能否在tomcat等容器中实现?
http://www.iteye.com/problems/5406

Spring对属性文件加密解密应用
http://voole.iteye.com/blog/632885

web项目加解密
http://xphwv.iteye.com/blog/1779031
tomcat中如何装载加密后的class文件
http://www.blogjava.net/jspark/archive/2006/07/25/59968.html

java源程序加密解决方案(基于Classloader解密)  **
http://cjnetwork.iteye.com/blog/851544#comments
http://www.ibm.com/developerworks/cn/java/l-secureclass/

http://blog.csdn.net/aesop_wubo/article/details/7582266
Encrypted classloader tomcat
http://www.coderanch.com/t/497275/Tomcat/Encrypted-files-classes-Tomcat
http://publib.boulder.ibm.com/infocenter/javasdk/v1r4m2/index.jsp?topic=%2Fcom.ibm.java.doc.diagnostics.142%2Fhtml%2Fid1100.html

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-331439-1-1.html 上篇帖子: 转:Tomcat配置HTTPS方式 下篇帖子: maven 发布到tomcat 记录
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表