jboss module依赖 问题

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

问题来源于 ovirt部署在jboss中,所用到的版本Jboss版本如下。

JBoss AS release: 7.5.4.Final-redhat-4 "Janus"
JBoss AS product: EAP 6.4.4.GA

而在我们开发的过程中,需要引入第三方的jar包,出现了很多问题,通过官网上的文档,以及各种尝试终于解决了以下几种场景的jar包引入的问题。

对于Jboss而言,有其类自定的类加载机制。所有的jar包都是一个module,所以需要以moudle的形式引入。而jboss又默认提供了一些通用的module,而对于jboss环境中没有提供的module,就需要我们自己在项目中生成一个module。分两种情况

  1. 系统提供的 static   module     多种应用 就可以使用同一个公用的jar。

    1. jboss目录中的modules文件夹下就提供了module,
    2. /jbossas/modules/system/layers/base/  目录下,就是提供了各module
    3. 如 commons-io,目录结构如下,
      [root@localhost main]# ls
      commons-io.jar  module.xml
      [root@localhost main]# pwd
      /usr/share/jbossas/modules/system/layers/base/org/apache/commons/io/main
      
      而该commons.jar指向了commons-io.jar -> /usr/share/java/commons-io-eap6/commons-io.jar ,而该版本为2.1.
    4. 如果我们需要在ovirt中引用commos-io的jar包,有两种方式,第一种是使用系统提供的module,则版本只能为2.1,而如果 不想使用系统提供的。则使用下面第二种方式,自己创建module。
    5. 而对于第一种引用,则直接在对应的project的 pom.xml引用相关的配置即可,version为2.1。
      1. 同时由于jboss的依赖问题,还需要在对应的MANIFEST.MF文件中添加Dependencies:commons-io。
      2. 或者在pox.xml中加入自动 生成的依赖
      3.  org.apache.commons.io

         

  2. 自己创建moudule

    1. 对于第三方的jar包,jboss没有提供的情况下,则需要在相应的project下,按照相应的目录格式,创建相应的modules.xml。同时将jar包传入即可,也可以通过pom.xml的形式导入.
  3. 对于依赖传递问题,A-B-C

以下摘自jboss官网文档

Module A depends on Module B and Module B depends on Module C. Module A can access the classes of Module B, and Module B can access the classes of Module C. Module A cannot access the classes of Module C unless:

  • Module A declares an explicit dependency on Module C, or

  • Module B exports its dependency on Module C.

如果A依赖于B,B依赖于C,A需要用到C,则需要在A的module中写入对C的依赖,或者在B的module中将C导出。

4.    Class Loading in Deployments

For the purposes of classloading all deployments are treated as modules by JBoss EAP 6. These are called dynamic modules. Class loading behavior varies according to the deployment type.

WAR Deployment

A WAR deployment is considered to be a single module. Classes in the WEB-INF/lib directory are treated the same as classes in WEB-INF/classes directory. All classes packaged in the war will be loaded with the same class loader.

EAR Deployment

EAR deployments are made up more than one module. The definition of these modules follows these rules:

  1. The lib/ directory of the EAR is a single module called the parent module.

  2. Each WAR deployment within the EAR is a single module.

  3. Each EJB JAR deployment within the EAR is a single module.

Subdeployment modules (the WAR and JAR deployments within the EAR) have an automatic dependency on the parent module. However they do not have automatic dependencies on each other. This is called subdeployment isolation and can be disabled on a per deployment basis or for the entire application server.

Explicit dependencies between subdeployment modules can be added by the same means as any other module.

Report a bug

5. Class Loading Precedence

The JBoss EAP 6 modular class loader uses a precedence system to prevent class loading conflicts.

During deployment a complete list of packages and classes is created for each deployment and each of its dependencies. The list is ordered according to the class loading precedence rules. When loading classes at runtime, the class loader searches this list, and loads the first match. This prevents multiple copies of the same classes and packages within the deployments class path from conflicting with each other.

The class loader loads classes in the following order, from highest to lowest:

  1. Implicit dependencies.

    These are the dependencies that are added automatically by JBoss EAP 6, such as the JAVA EE APIs. These dependencies have the highest class loader precedence because they contain common functionality and APIs that are supplied by JBoss EAP 6.

    Refer to Section 3.7.1, “Implicit Module Dependencies” for complete details about each implicit dependency.

  2. Explicit dependencies.

    These are dependencies that are manually added in the application configuration. This can be done using the application's MANIFEST.MF file or the new optional JBoss deployment descriptor jboss-deployment-structure.xml file.

    Refer to Section 3.2, “Add an Explicit Module Dependency to a Deployment” to learn how to add explicit dependencies.

  3. Local resources.

    Class files packaged up inside the deployment itself, e.g. from the WEB-INF/classes or WEB-INF/libdirectories of a WAR file.

  4. Inter-deployment dependencies.

    These are dependencies on other deployments in a EAR deployment. This can include classes in the libdirectory of the EAR or classes defined in other EJB jars.

 

 

 

https://access.redhat.com/documentation/zh-CN/JBoss_Enterprise_Application_Platform/6.1/html/Migration_Guide/Find_the_JBoss_Module_Dependency1.html    查找 JBoss 模块依赖关系

 

https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.1/html/Development_Guide/chap-Class_Loading_and_Modules.html#Overview_of_Class_Loading_and_Modules-1

https://my.oschina.net/iwuyang/blog/197231

http://jbosscn.iteye.com/blog/1143426  jboss modules介绍

http://blog.csdn.net/andyelvis/article/details/6719996 tomcat classpath 类加载介绍

转载于:https://my.oschina.net/ovirtKg/blog/742895

你可能感兴趣的:(jboss module依赖 问题)