JBoss - War library dependencies

前端 未结 2 644
遇见更好的自我
遇见更好的自我 2021-01-15 16:41

I am trying to add some dependencies jar files. But these files when put in lib/endorsed or in WEB_INF/lib.jar results in startup error for jboss i

2条回答
  •  暖寄归人
    2021-01-15 17:41

    Duffymo's directive on not putting jars in endorsed is ignored at your peril.

    In some additional detail:

    Placing libraries in your WEB-INF/lib is a best practice for portability and consistency as it adheres to a standard provision for creating self-sufficient and distributable web archives, but you need to pay close attention to the class-loading declaration you're putting in your jboss-web.xml.

    Assume a simple scenario without the class-loading declaration and a fictional example.jar:

    • If you place example.jar in WEB-INF/lib and it does not also exist in jboss//lib, then example.jar will only be visible to that specific WAR.
    • If you place example.jar in WEB-INF/lib and it does also exist in jboss//lib, the instance in WEB-INF/lib will essentially be ignored and the WAR will use the JBoss server instance's unified class loader to load the example classes from jboss//lib/example.jar. (The same would apply to any other WARs or EARs in the same server instance, assuming no class-loading overrides.)

    The class-loading declaration is necessary in cases (such as) where you have two different versions of example.jar: - jboss//lib: example1.0.jar - WEB-INF/lib: example2.0.jar

    In this case, JBoss will create a unique and isolated classloader for your WAR which will avoid jboss//lib/example1.0.jar in favour of WEB-INF/lib/example2.0.jar in the context of your WAR.

    In summary, if you're only running one WAR in the jboss server instance and/or you have no conflicting JAR issues, ditch the class-loading declaration and put your JARs in jboss//lib. It makes the WAR file more lightweight, overall deployment may be simpler and you will not consume additional memory with extra class versions during hot-deploys.

提交回复
热议问题