Skinny WAR, libraries in EAR: “struts-tags not fou

2020-01-29 12:24发布

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:


Struts has detected an unhandled exception:
Messages:
File "/struts-tags" not found
File: org/apache/jasper/compiler/DefaultErrorHandler.java
Line number: 51

Stacktraces
org.apache.jasper.JasperException: File "/struts-tags" not found
...........
...........

How to resolve this problem ?

1条回答
姐就是有狂的资本
2楼-- · 2020-01-29 13:08

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" %>
查看更多
登录 后发表回答