简体   繁体   English

封装在EAR文件中的JAR文件中的JSP taglib

[英]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. taglib.jar :打包为JAR文件的自定义JSP taglib。 The TLD file is /META-INF/taglib.tld . TLD文件是/META-INF/taglib.tld
  • webapp.war : A web application with JSP files that use the tags provided by taglib.jar . webapp.war :包含使用taglib.jar提供的标记的JSP文件的Web应用程序。
  • app.ear : A J2EE application which contains webapp.war and other WAR files. app.ear :包含webapp.war和其他WAR文件的J2EE应用程序。

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. 我要打包一个taglib.jarapp.ear所以在JSP文件webapp.war和其他WAR文件都可以使用它的标签。 I tried the following directives in the JSP files, without success: 我在JSP文件中尝试了以下指令,但没有成功:

  • <%@ 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? 是否可以将JSP taglib JAR文件打包到EAR文件中? If yes, which value should I specify in the uri attribute of the taglib directive? 如果是,我应该在taglib指令的uri属性中指定哪个值?

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. 注意:我当然可以在每个WAR文件的/WEB-INF/lib中打包taglib.jar ,但这正是我试图避免的。

Context: I deploy the EAR file on JBoss 4.2.3. 上下文:我在JBoss 4.2.3上部署EAR文件。

Edit: I'm afraid this is impossible, especially since I read the section about skinny WARs from the Maven WAR plugin documentation : 编辑:我担心这是不可能的,特别是因为我从Maven WAR插件文档中读到了关于skinny WARs的部分

Sometimes a list of JARs must be packaged into the WAR (...) in order for it to work properly, like with tag libraries. 有时,必须将JAR列表打包到WAR(...)中才能使其正常工作,就像使用标记库一样。

The jar taglib's can be only present under WEB-INF/lib. jar taglib只能出现在WEB-INF / lib下。 The container might provider some custom way to configure the commonly used tld. 容器可能提供一些自定义方式来配置常用的tld。 To achieve the same in JBOSS, this is the way 为了在JBOSS中实现同样的目标,这就是方法

The JspServlet supports a new engineOptionsClass that allows the options implementation to be replaced. JspServlet支持新的engineOptionsClass,允许替换选项实现。 The default setting now uses the jboss specific JspServletOptions: 默认设置现在使用jboss特定的JspServletOptions:

engineOptionsClass org.jboss.web.tomcat.tc5.jasper.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. 然后使用自定义标记lib描述符缓存org.jboss.web.tomcat.tc5.jasper.TagLibCache从tomcat sar conf / tlds中的jar加载标记库。

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). 这是一个古老的主题,但我想分享我的解决方案:在eclipse上用鼠标右键单击项目,导出为带有“导出生成的类文件和资源”选项的jar并为其命名(ex.customtags。罐)。 Open the packaged .jar with 7Zip and we should see a structure similar to the following: 使用7Zip打开打包的.jar,我们应该看到类似于以下的结构:

  • com COM
  • META-INF META-INF
  • webapp Web应用程序
  • .classpath 的.classpath

Copy all the taglibs to the META-INF folder at the root of the .jar file (not any other location). 将所有taglib复制到.jar文件根目录下的META-INF文件夹(不是任何其他位置)。

After changing this jar add this to the webapp\\WEB-INF\\lib folder of the project you want to use the taglib. 更改此jar后,将其添加到要使用taglib的项目的webapp \\ WEB-INF \\ lib文件夹中。 On the jsp file put the following: 在jsp文件中输入以下内容:

This should work just fine! 这应该工作得很好!

Regards, MS 此致,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. 我能做的最好的事情是在EAR文件中打包taglib.jar ,并在每个WAR文件的/WEB-INF目录中复制TLD文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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