管理java类路径上的冲突

编程入门 行业动态 更新时间:2024-10-27 02:26:30
本文介绍了管理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类路径上的冲突

本文发布于:2023-10-30 03:21:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541616.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   冲突   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!