如何将JBoss AS7提供的JSF放在JAR模块的类路径上? [英] How to put JSF provided by JBoss AS7 on the classpath of a JAR module?

查看:121
本文介绍了如何将JBoss AS7提供的JSF放在JAR模块的类路径上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概述:我有一个JEE6项目,该项目使用 Apache Maven 作为构建系统.我的项目产生了一个EAR,其中包含一些常见的JAR,一些EJB模块和一个WAR.产生的EAR应该部署到 JBoss AS 7 (目前为7.1.1).

Overview: I have a JEE6 project that uses Apache Maven as the build system. My project produces an EAR that contains some common JARs, some EJB modules and a WAR. The produced EAR should be deployed to JBoss AS 7 (7.1.1 for now).

最佳做法:如果您有一个Web应用程序(例如我的),并且该Webapp的类(托管Bean)可能在其他项目中重用,则它是

Best practices: If you have a web-application (like mine) and the classes for the webapp (managed beans) might be reused in other projects, it is the recommended way (the maven way) to package these classes into a separate JAR and make the WAR depend on this JAR. The JAR is then packaged with the EAR (but not inside the WAR). So far everything is working fine.

这是我的EAR的布局:

Here is the layout of my EAR:

EAR
 +-- lib
 |    +-- [some 3rd party JARs]
 |    `-- war-backingbeans.jar
 +-- myEJBs.jar
 `-- myWAR.jar

问题:当我的backingbeans JAR中的类根据某些JSF类(如FacesContext)启动时,就会出现问题. JBoss AS7附带了JSF JAR,并自动在类路径中为WAR提供了这些JAR.但是,这些JAR不在EAR的类路径或EAR中的其他JAR上.

Problem: The problem arises, when the classes in my backingbeans JAR start depending on some JSF classes like FacesContext. JBoss AS7 comes with JSF JARs included and provides theses JARs for WARs on the classpath automatically. However, these JARs are not on the classpath of the EAR or other JARs in the EAR.

我可以在Maven端对相关的JAR添加一个相应的依赖关系,但是最终将JSF JAR打包到EAR中.我实际上想要的是JBoss,将其JSF JAR放在JAR的类路径中.

I could just add a corresponding dependency on the relevant JAR on the maven side, but that would end up with the JSF JARs packaged into the EAR. What I would actually like is JBoss to put it's JSF JARs on the classpath of the JAR.

我通过提供META-INF目录中的> jboss-deployment-structure.xml 文件,内容如下:

I found a solution for this by providing a jboss-deployment-structure.xml file in the META-INF directory of the EAR with the following content:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
  <deployment>
    <dependencies>
      <module name="javax.faces.api" slot="main" export="true"/>
    </dependencies>
  </deployment>
</jboss-deployment-structure>

我的问题是现在,我是按照正确的方式进行操作还是将其视为黑客?是否有更好/更便携的解决方案来解决我的问题?

My question is now, am I doing it the right way or is this considered a hack? Are there better/more portable solutions to my problem?

非常感谢,
-马丁

Many thanks in advance,
- martin

推荐答案

JBoss AS 7自动将一些模块添加到您的应用程序/ear的类路径中.您可以在此处找到完整列表.此列表提到了用于Web子系统的javaee.api和com.sun.jsf-impl,因此您无需在jboss-deployment-structure中添加它们.

JBoss AS 7 automatically adds some modules to the classpath of your application/ear. You can find a complete list here. This list mentions javaee.api and com.sun.jsf-impl for the web subsystem, hence you don't need to add them with your jboss-deployment-structure.

但是,如果您执行更多高级选项,例如,jboss-deployment-structure文件将是必需的.如果要使用与JBoss一起提供的版本不同的JSF版本而不更换模块.然后,您可能需要阅读.

But the jboss-deployment-structure file will be necessary if you do more advanced options, e.g. if you want to use a different JSF version than the one shipped with JBoss without replacing the module. You then may want to read this.

因此,据我从您的描述中所看到的,您不需要jboss-deployment-structure.只需将您的jsf maven依赖项的范围设置为provided.

Thus, as far as I can see from your description, you don't need the jboss-deployment-structure. Just set the scope for your jsf maven dependencies to provided.

这篇关于如何将JBoss AS7提供的JSF放在JAR模块的类路径上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆