什么是类路径地狱?对于Java来说确实是一个问题吗? [英] What is classpath hell and is/was it really a problem for Java?

查看:138
本文介绍了什么是类路径地狱?对于Java来说确实是一个问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是类路径地狱?对于Java来说确实是一个问题吗?

What is classpath hell and is/was it really a problem for Java?

推荐答案

类路径地狱是Java进行的那种动态链接的不幸结果.

Classpath hell is an unfortunate consequence of dynamic linking of the kind carried out by Java.

您的程序不是固定的实体,而是JVM在特定实例中加载的一组确切的类.

Your program is not a fixed entity but rather the exact set of classes loaded by a JVM in a particular instance.

由于解析规则,在不同平台上甚至同一平台上使用同一命令行可能会导致完全不同的结果.

It is very possible to be in situations where the same command line on different platforms or even on the same one would result in completely different results because of the resolution rules.

标准库中可能存在差异(非常常见).图书馆可以彼此隐藏(甚至可以使用较旧的版本代替较新的版本).目录结构可能会使解析混乱.同一类的不同版本可能会出现在多个库中,并且将使用遇到的第一个库,依此类推.由于Java按照规范使用了第一个遇到的策略,因此未知的排序依存关系可能会导致问题.当然,由于这是命令行并且是规范的一部分,因此没有真正的警告.

There could be differences in standard libraries (very common). Libraries could be hidden by one another (an an older version may even be used instead of a newer one). The directory structure could mess resolution. A different version of the same class may appear in multiple libraries and the first one encountered will be used, etc. Since Java, by specification, uses a first-encountered policy, unknown ordering dependencies can lead to problems. Of course, since this is the command line and it is part of the spec, there are no real warnings.

这仍然是一个大问题.例如,在Mac OS上,Apple的可怕支持意味着您的计算机最终会带有多个JVM和几个JRE,并且您永远都不可能轻易地随意放置东西.如果您有针对特定但不同版本的其他库编译的多个库,则可能会遇到问题等.

It is very much still a problem. For example on Mac OS the horrible support from Apple means that you machine ends up with several JVMs and several JREs, and you can never easily poart things from place to place. If you have multiple libraries that were compiled against specific but different versions of other libraries, you coulld have problems, etc.

但是,此问题不是Java固有的.我记得在90年代编程Windows时遇到的DLL地狱情况.在任何情况下,您都必须依靠文件系统中的某些东西来组装程序,而不是拥有一个定义明确的可执行文件,这是一个问题.

However, this problem is not inherent in Java. I remember my share of DLL hell situations while programming windows in the 90s. Any situation where you have to count on something in the file system to assemble your program rather than having a single well defined executable is a problem.

但是,此模型的好处仍然很大,因此我愿意容忍这种地狱. Sun方面也朝着正确的方向迈出了一步.例如,Java6允许您仅使用jar指定目录,而不必枚举它们.

However, the benefits of this model are still great, so I'm willing to tolerate this hell. There are also steps in the right direction on the side of Sun. For example, Java6 allows you to simply specify a directory with jars rather than have to enumerate them.

顺便说一句:如果您使用的环境使用非默认的类加载器,则类路径也是一个问题.例如,由于类加载器不兼容,我在Eclipse下运行诸如Hibernate或Digester之类的程序时遇到了很多问题.

BTW: Classpaths are also a problem if you are using an environment that uses a non-default classloader. For example, I have had a lot of problems running things like Hibernate or Digester under Eclipse because the classloaders were incompatible.

这篇关于什么是类路径地狱?对于Java来说确实是一个问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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