Order of class loading from a .war file

前端 未结 6 791
南方客
南方客 2020-12-09 10:45

I\'ve got a question regarding the guarantees, if any, in the following scenario (note that the question is not \"How to do this in a different way?\", the question

6条回答
  •  轮回少年
    2020-12-09 11:31

    The answer depends entirely on the concrete class loader hierarchy in use. While the JVM will provide a system class loader, Java EE application servers will typically use custom ClassLoader implementations to isolate classes loaded in separate modules and applications, and to enforce security concerns.

    The ClassLoader API does not impose any rules on how concrete implementations resolve class requests. However, the intent of the WEB-INF/lib directory is to allow bundling of app-specific libraries. I suspect most people would expect the jar files in the lib directory to be searched AFTER the root contents of the jar file.

    I'm not aware that the Java EE specifications establish any such guarantee though, and the interface and documentation for the abstract ClassLoader class certainly doesn't.

    So, hypothetically, you could have a web container that would end up returning Bunny.class from the jar file instead of the one from the root hierarchy of the war file.

提交回复
热议问题