How Does WebSphere Choose the Classloading Order in a Folder (WEB-INF/lib)

南楼画角 提交于 2021-01-27 13:22:46

问题


I am currently facing an interesting problem where our application fails to start up on 3/4 nodes due to classloading issues.

The problem seems to be that WAS is loading b.jar before a.jar. After troubleshooting more, I found that all of the nodes load the jars in different orders (via Classpath viewer in console) and the working node may have just been a fluke.

How does WebSphere determine the classloading order within an installed applications WEB-INF/lib folder?


回答1:


Order of loading jars is undefined in websphere. To solve your problem I can suggest you to use one of the below option.

Use manifest classpath settings by mentioning the jar names in a order like how you want them to be loaded.

OR

You can extract the classes from a.jar and put it in the WEB-INF/classes directory. Then remove a.jar from the lib folder. Because classes directory will be loaded before lib directory.




回答2:


There are 2 ways you can configure the classloader in Websphere, PARENT_FIRST (default) or PARENT_LAST. Classloaders in Websphere are hierarchical, you can think of it as a tree where you have: Java class loader -> ext class loader -> App module class loader -> web module class loader

PARENT_FIRST will load classes from the "top down" starting with the Java class loaders, whereas PARENT_LAST will load the classes from the "bottom up" starting with the web module class loader. If you are using open source libraries that conflict with WAS-shipped libraries, I would suggest that you use PARENT_LAST.

Take a look at these resources for more info:

  • http://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/crun_classload.html

  • http://www.ibm.com/support/knowledgecenter/SSAW57_8.0.0/com.ibm.websphere.nd.doc/info/ae/ae/urun_rclassloader_inst.html



来源:https://stackoverflow.com/questions/40424458/how-does-websphere-choose-the-classloading-order-in-a-folder-web-inf-lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!