开发者

Difference betwen classpath and lib folder

开发者 https://www.devze.com 2023-03-15 05:47 出处:网络
One thing i haven\'t been able to figure out(only 4 months of experience in J2EE), is the scope of the classpath and lib folder(WEB-INF/...)

One thing i haven't been able to figure out(only 4 months of experience in J2EE), is the scope of the classpath and lib folder(WEB-INF/...) Why 2 places for loading classes? At server startup-time, what are the classes that are "read" first? Why load开发者_运维百科ing all classes in classpath will not be sufficient?

Thank you


The application server will look in the module's lib directory first, then in the global class path--if at all.

Typically, classes loaded through the application server's global class-path cannot be replaced at runtime. That means you have to stop and re-start the entire application server to upgrade or replace code and that is often not acceptable in production environments. It also means the classes and jar files of your application or module might conflict with the application server's own code, or with other applications deployed to the same application server.

The documentation of the application server you are using will probably either prohibit or strongly discourage modification of the global class path.

Application servers typically create a separate class loader instance for each application. Doing so allows the application server to isolate the code dependencies of each application, and makes it possible to reload or even unload modules.

The current class loader model that has been with Java since the beginning can be difficult to understand and quickly leads to very complicated issues. Unfortunately, a lot of those issues are often first encountered in the integration test and production environment. Frameworks like OSGi attempt to address some of those problems and there are various initiatives under the JCP process to improve class loading and dependency management as well within the Java specifications.

0

精彩评论

暂无评论...
验证码 换一张
取 消