Websphere 类加载
我们在 Websphere 应用程序服务器 7 中部署了一个应用程序。它在各种环境中部署和运行。但它在一个新环境中给出了未找到方法的异常。经过深入挖掘,我们发现一个特定的类存在于 2 个 jar 中,并且来自“错误”jar 的类被加载到新的环境中。我浏览了详细的类加载器视图,其中 jar 的加载顺序有所不同。
经过进一步调查,每个环境中加载 jar 文件的顺序似乎存在随机差异。
2个问题:
1)WAS类加载策略取决于哪个因素?有什么建议可以纠正这个问题吗?
2)更一般地,当我们在任何java程序的类路径中指定假设*.jar时,JVM如何加载jar?比如它是按字母顺序还是根据修改时间或任何此类文件属性?
We have an application deployed in Websphere application server 7. Its deployed and functioning in various environments. But it gave a method not found exception in one new env. On digging deeper we found that a particular class was present in 2 jars and the class from the "wrong" jar was getting loaded in the new env. i went through the detailed class loader view and the sequence of the loading of jars were different in it.
On further investigation there seemed to be random variance in the order in which the jar files were loaded in each env.
2 questions:
1) On which factor does the WAS class loading policy depend & any suggestion for rectifying the problem?
2) More generally when we specify supposing *.jar in the classpath for any java program how does any JVM load the jars? Like is it alphabetical or according to time modified or any such file property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 WAS 下安装 Web 应用程序时,您可以在该应用程序的选项中设置类加载策略(或在服务器/节点级别全局设置)
如果策略选项是(搜索)“父级优先”/“父级最后”和一个类加载器每个应用程序或每次战争。默认为“父级优先/战争”。如果您的网络应用程序附带了它需要的所有 jars,那么您最好将策略设置为“父级最后/应用程序”。此外,如果您编辑 web.xml 以反映更改,请务必设置“使用二进制配置”,否则它将始终使用安装期间存储的内容。
When installing web-apps under WAS, you can set the classloading policy in the options for that application (or globally on server/node level)
If the policy options are (search) "parent first" / "parent last" and one class loader per application or per war. The default is "parent first / war". If your web-app comes with all jars it needs you'll be better off with the policy set to "parent last / application". Also if you edit your web.xml to reflect changes, be sure to set "use binary configuration" otherwise it will always use what it stored during install.
Java 按照类路径中指定的顺序加载类。因此,如果您的类路径是“c:\jar1.jar;c:\jar2.jar”并且 jar1.jar 和 jar2.jar 包含相同的类,则将始终使用 jar1.jar 中的类。如果顺序颠倒,则将始终使用 jar2.jar 类。
维基百科解释了类加载器如何很好地工作 http://en.wikipedia.org/wiki/Java_Classloader
可以通过服务器上的 WAS 管理控制台在“服务器”>“服务器”下配置类路径。流程定义> Java 虚拟机
也可以按应用程序进行配置。
Java loads classes in the order they are specified in the classpath. So if your classpath is "c:\jar1.jar;c:\jar2.jar" and jar1.jar and jar2.jar contain the same class, the class from jar1.jar will always be used. If the order was reversed, then the jar2.jar class would always be used.
Wikipedia explains how Class Loaders work pretty well http://en.wikipedia.org/wiki/Java_Classloader
The classpath can be configured through the WAS Admin Console on the Server under Server > Process Definition > Java Virtual Machine
It can also be configured per application.
你在问非常大的问题。要解决您的问题,有 2 个选项:
You're asking very big questions. To solve your problem there're 2 options: