简体   繁体   中英

JSP taglib in a JAR file packaged in an EAR file

I have the following situation:

  • taglib.jar : A custom JSP taglib packaged as a JAR file. The TLD file is /META-INF/taglib.tld .
  • webapp.war : A web application with JSP files that use the tags provided by taglib.jar .
  • app.ear : A J2EE application which contains webapp.war and other WAR files.

I want to package a single taglib.jar in app.ear so the JSP files in webapp.war and the other WAR files can all use its tags. I tried the following directives in the JSP files, without success:

  • <%@ taglib uri="/taglib.jar" prefix="xxx" %>
  • <%@ taglib uri="taglib.jar" prefix="xxx" %>

Is it possible to package the JSP taglib JAR file in an EAR file? If yes, which value should I specify in the uri attribute of the taglib directive?

Note: I could of course package taglib.jar in the /WEB-INF/lib of each WAR file, but that is just what I try to avoid.

Context: I deploy the EAR file on JBoss 4.2.3.

Edit: I'm afraid this is impossible, especially since I read the section about skinny WARs from the Maven WAR plugin documentation :

Sometimes a list of JARs must be packaged into the WAR (...) in order for it to work properly, like with tag libraries.

The jar taglib's can be only present under WEB-INF/lib. The container might provider some custom way to configure the commonly used tld. To achieve the same in JBOSS, this is the way

The JspServlet supports a new engineOptionsClass that allows the options implementation to be replaced. The default setting now uses the jboss specific JspServletOptions:

engineOptionsClass org.jboss.web.tomcat.tc5.jasper.JspServletOptions

which in turn uses a custom tag lib descriptor cache org.jboss.web.tomcat.tc5.jasper.TagLibCache that loads tag libs from jars in the tomcat sar conf/tlds.

This is an old topic but I want to share my solution: On eclipse right-click with mouse on the project, export as a jar with the option "Export generated class files and resources" and give a name to it (ex.customtags.jar). Open the packaged .jar with 7Zip and we should see a structure similar to the following:

  • com
  • META-INF
  • webapp
  • .classpath

Copy all the taglibs to the META-INF folder at the root of the .jar file (not any other location).

After changing this jar add this to the webapp\\WEB-INF\\lib folder of the project you want to use the taglib. On the jsp file put the following:

This should work just fine!

Regards, MS

This is not possible. The best I could do is to package taglib.jar in the EAR file, and duplicate the TLD file in the /WEB-INF directory of each WAR file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM