WildFly Modules: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 151: Line 151:
==Expressing a Dependency on a Dynamic Module==
==Expressing a Dependency on a Dynamic Module==


It is possible for a deployment to import classes - declare a dependency - on another deployment, using the other deployment's ''dynamic module name''.
It is possible for a deployment to import classes - declare a dependency - on another deployment, using the other deployment's [[#Deployment_Module_Names|dynamic module name]]:
 
<pre>
<jboss-deployment-structure>
    <ear-subdeployments-isolated>true</ear-subdeployments-isolated>
 
    ...
 
    <sub-deployment name="B-services.jar">
        <dependencies>
              …
              <module name="deployment.myapp.ear.A-services.jar"/>
        </dependencies>
    </sub-deployment>
</jboss-deployment-structure>
</pre>


==JDK Classes==
==JDK Classes==

Revision as of 13:43, 23 February 2017




Migrating from https://home.feodorov.com:9443/wiki/Wiki.jsp?page=JBossModules


External

Internal

Overview

A WildFly module (or JBoss module) is a packaged collection of classes and other resources, along with the specification of what is imported and exported by this module from/to other modules. Each API or service provided by WildFly is implemented as a module, which is loaded or unloaded on demand.

WildFly modules provide finely grained class isolation. They hide server implementation classes from the application and only load the classes the application needs. WildFly modules are peers that remain isolated unless explicitly defined as a dependency of another module. Visibility rules have sensible defaults and can be customized.

JEE deployments (see below) are also modules, which do not have access to application server modules' classes, unless an explicit dependency on those classes is defined.

For more details on class loading see

WildFly class loading

Operations

TODO: how can I get a list (hierarchy) of all modules deployed within an instance, at runtime?

Statically Deployed Modules

Statically deployed modules go under $JBOSS_HOME/modules directory.

Each module has a module.xml descriptor.

JEE Deployment Modules

WAR Deployments

A WAR deployment creates a single module at runtime. Classes defined in WEB-INF/lib and WEB-INF/classes are treated similarly from a visibility point of view. All classes packaged in the WAR will be loaded by the same class loader.

EAR Deployments

An EAR deployment creates multiple modules:

  • One module corresponding to EAR's /lib directory.
  • Modules corresponding to every WAR and EJB deployments. These have an automatic dependency on the parent EAR module, which gives them automatic access to EAR's /lib content.

The name of the EAR module is similar to: "deployment.my-ear-2.0.ear". If the EJB was deployed within an EAR, the name is similar to "deployment.my-ear-app-2.0.ear.my-ejb-services-2.0.jar". For more details on the names, see Deployment Module Names below.

Because the deployment process creates distinct modules corresponding to the WAR and EJB deployments, not all classes inside the EAR will necessarily have access to all other classes in the EAR, unless explicit dependencies have been defined or "ee" subystem's configuration parameter ear-subdeployments-isolated is set to false. For more details on ear-subdeployments-isolated see:

"ee" Subsystem ear-subdeployments-isolated

Dependencies: Manifest Entries

TODO, see https://docs.jboss.org/author/display/AS71/Developer+Guide#DeveloperGuide-EARClassLoading.

Also see:

MANIFEST.MF

Class-Path: Manifest Entries

TODO, see https://docs.jboss.org/author/display/AS71/Developer+Guide#DeveloperGuide-ClassPathEntries.

Also see:

MANIFEST.MF

Deployment Module Names

Each JEE deployment triggers run-time initialization of corresponding module or set of modules.

A top-level deployment that does not have any other sub-deployments creates a single module named deployment.<my-archive-name>.war:<version>.

Example for a simple servlet deployment:

deployment.servlet-example.war:main

Sub-deployments are named according to the following pattern: deployment.<my-ear-archive-name>.ear.<my-war-archive-name>.war.

Global Modules

It is possible to set up global modules that are accessible to all JEE deployments:

<subsystem xmlns="urn:jboss:domain:ee:1.2">           
  <global-modules>
    <module name="io.novaordis.playground.wildfly.custommodule" slot="1.0" />            
  </global-modules> 
</subsystem>

For more details on configuring global modules see:

Global Module configuration

"ee" Subsystem Configuration

For more details on "ee" subsystem configuration see:

ee Subsystem Configuration

Inter-Module Dependencies

Implicit Dependencies

Some dependencies on modules defined by the application server are set up automatically for JEE deployments, making them implicit dependencies. An obvious example is JEE APIs. When a deployment is being processed by the server, it goes through a chain of deployment processors. Each of these processors has the option to add implicit module dependencies to that deployment. For example, the presence of the @Stateless annotation identifies this deployment as an EJB deployment to the EJB deployment processor, so the processor will add an implicit dependency on the Java EE API module, so that all the Java EE API classes are visible to the deployment.

Automatic dependencies can be excluded through the use of the jboss-deployment-structure.xml deployment descriptor.

More details on Implicit module dependencies for deployments are available here:

https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments

Explicit Dependencies

Dependencies on other modules can (and must) be expressed explicitly. The most common way to do that is to declare the dependency on the module in jboss-deployment-structure.xml

Declaring a dependency on another module in jboss-deployment-structure.xml

The dependency on a module can also be declared in the MANIFEST.MF of the JAR containing the classes that need to access the module. More details available here

How to specify a dependency on a JBoss Module in JBoss EAP 6/7 https://access.redhat.com/solutions/341703

If we need to express a dependency across a number of JEE deployments, global modules could help:

Global Modules

Expressing a Dependency on a Dynamic Module

It is possible for a deployment to import classes - declare a dependency - on another deployment, using the other deployment's dynamic module name:

<jboss-deployment-structure>
    <ear-subdeployments-isolated>true</ear-subdeployments-isolated>

    ...

    <sub-deployment name="B-services.jar">
        <dependencies>
              …
              <module name="deployment.myapp.ear.A-services.jar"/>
        </dependencies>
    </sub-deployment>
</jboss-deployment-structure>

JDK Classes

sun.jdk is automatically added as a dependency to all deployments, but not all JDK classes are exposed to deployments by default, but specific classes or packages can be added as dependencies using jboss-deployment-structure.xml.

See:

jboss-deployment-structure.xml - accessing JDK Classes

Writing a Custom WildFly Module

Writing a Custom WildFly Module

Source

https://github.com/dmlloyd/jboss-modules

Organizatorium

Upon the first use of the module, JBoss creates a <module-name>.jar.index file containing a list of packages? directories? .... .