使用相同的包和类名动态管理两个jar文件 [英] Dynamically manage two jar files with the same package and class names

查看:214
本文介绍了使用相同的包和类名动态管理两个jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从客户端有两个jar文件,其中一个用于测试,另一个用于最终版本。目前,我将它们放在不同的文件夹中,并在部署代码时修改库路径,但是能够在运行时动态加载这两个jar文件并在它们之间切换是很好的。

I have two jar files from a client, one of which is used for a testing and another for final versions. Currently I put them in different folders and modify the library path when deploying our code, but it would be nice to be able to load both jar files and switch between them dynamically at runtime.

这是否可能?

推荐答案

您可以随时编写自己的ClassLoader并使用标准ClassLoader链接。

You can always write your own ClassLoader and chain it with the standard ClassLoader.

http://download.oracle.com/javase/6 /docs/api/java/lang/ClassLoader.html

10年前我使用这种方法加载通过套接字接收的类,并在XML文件(通过套接字)。我的java程序不知道这些类在获得XML文件和类之前已经存在。

I used this method 10 years ago to load classes that were recieved via sockets and specified in an XML file (via sockets as well). My java program didn't know that the classes even existed before it got the XML file and the classes.

这篇关于使用相同的包和类名动态管理两个jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆