管理java类路径上的冲突 [英] manage conflict on java classpath

查看:182
本文介绍了管理java类路径上的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公开了我的上下文:



我有两个Java程序运行在一个独特的Weblogic服务器上:程序A和程序B.
这些启动通过两个ksh:



programA.ksh和programB.ksh



都需要C.jar,但在不同的版本(但具有完全相同的包和类):




  • 程序需要C-1.0.jar

  • 程序B需要C-2.0.jar



我确切地说,两个程序共享相同的weblogic类路径。



所以,我的类路径按照这个顺序包含:



.....



C-1.0.jar



C-2.0.jar



.....

如何才能使每个程序找到它的好库?



例如,通过我的实际配置,程序B将始终使用C-1.0.jar而不是C-2.0.jar,因为classpath中的优先级位置。

解决方案

如果你推出两个这两个程序的JVM的实例实例,然后不要使用相同的类路径!不是很明显吗?



你可能使用CLASSPATH环境变量?这是一个非常老的,过时的做法,你不应该这样做。使用-classpath命令行参数,这样就可以轻松地为两个程序使用不同的类路径。



旧答案:
假设你在谈论线程而不是进程:



最好的解决方案是修复A,B或C,以便A和B都可以使用相同的版本的C。



或者,如果两个版本的C实际上有故意不同的行为,请为其使用不同的包或类名。



只有当您不能更改A,B或C时,如果您考虑使用不同的类加载器,以便他们看到不同版本的C。


I expose my context :

I have two Java programs that run on a unique Weblogic Server : program A and program B. These ones are launched by two ksh :

programA.ksh and programB.ksh

Both need C.jar but in different versions (but with exactly the same package and classes) :

  • program A need C-1.0.jar
  • program B need C-2.0.jar

I precise that both programs share the same weblogic classpath.

So, my classpath contains in that order :

.....

C-1.0.jar

C-2.0.jar

.....

How can I do so that each program finds its good library ?

For instance, with my actual configuration, program B will always use C-1.0.jar instead of C-2.0.jar because of the priority position on classpath.

解决方案

If you launch two separate instances of the JVM for the two programs, then don't use the same classpath! Isn't that obvious?

Are you perhaps using the CLASSPATH environment variable? That is a very old, outdated practice and you should not do it. use the -classpath command line parameter, that way you can easily use different classpaths for the two programs.

Old answer: Assuming that you're talking about threads rather than processes:

The best solution would be to fix A, B or C so that both A and B can use the same version of C.

Or, if the two versions of C actually have intentionally different behaviour, use a different package or class names for them.

Only if you cannot change A, B or C should you consider the technical solution of writing a wrapper that uses different classloaders for A and B so that they will see different versions of C.

这篇关于管理java类路径上的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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