Skinny WAR, libraries in EAR: “struts-tags not found” error

后端 未结 1 1945
孤城傲影
孤城傲影 2020-12-03 20:17

In a Java EE project, I moved all the libraries from the WAR/WEB-INF/lib to the EAR/lib.

Opening a JSP, now I get this error:

相关标签:
1条回答
  • 2020-12-03 21:10

    Moving the libraries from the WAR to the EAR may be very useful, e.g. if you have more than one WAR* inside one EAR, to avoid redundancy of libraries.
    * Note: With multiple WAR in Struts2, you may encounter problems in some application server: read more on the official documentation.


    To make a Skinny WAR (a WAR without libraries) work, the conditions are:

    1. The WAR's META-INF/MANIFEST.MF must contain a Class-Path property linking your libraries:

      Class-Path: lib/struts2-core-2.3.15.2.jar 
                  lib/xwork-core-2.3.15.2.jar     
                  lib/all_your_libraries_here...
      
    2. The EAR's application.xml must contain:

      <library-directory>lib</library-directory>.

    To achieve this conditions on Maven, without the need of declaring the dependency of each library of WAR's POM.xml in EAR's POM.xml, you can use this amazing trick.

    That said, the problem reported in the question is given by the fact that the TLD lookup is performed on the WAR only, the EAR is out of scope (AFAIK, there is no way to lookup a TLD in the EAR, but I'd like to be proven wrong).

    The solution:

    extract the struts-tags.tld from struts2-core-2.3.x.x.jar, and place it under (each) WAR/WEB-INF folder. This is related to any kind of TLD file inside a JAR, not only to Struts2.

    In JSP:

    <%@ taglib prefix="s" uri="/WEB-INF/struts-tags.tld" %>
    
    0 讨论(0)
提交回复
热议问题