WildFly Modules: Difference between revisions
Line 46: | Line 46: | ||
=JEE Deployment Modules= | =JEE Deployment Modules= | ||
==WAR Deployments== | ==WAR Deployments== |
Revision as of 14:13, 23 February 2017
External
- JBoss Modules Documentation (old) https://docs.jboss.org/author/display/MODULES/Home
- Binaries https://repository.jboss.org/nexus/content/repositories/releases/org/jboss/modules/jboss-modules/
- JIRA https://issues.jboss.org/projects/MODULES
- Layered Distributions and Module Path Organization by Brian Stansberry https://developer.jboss.org/wiki/LayeredDistributionsAndModulePathOrganization
Internal
- WildFly
- Java Modules
- Modular Service Container
- Class Loading
- jboss-deployment-structure.xml
- module.xml
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
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:
Dependencies: Manifest Entries
TODO, see https://docs.jboss.org/author/display/AS71/Developer+Guide#DeveloperGuide-EARClassLoading.
Also see:
Class-Path: Manifest Entries
TODO, see https://docs.jboss.org/author/display/AS71/Developer+Guide#DeveloperGuide-ClassPathEntries.
Also see:
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:
"ee" Subsystem Configuration
For more details on "ee" subsystem configuration see:
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:
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
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:
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:
Writing a Custom WildFly Module
Source
Organizatorium
- Upon the first use of the module, JBoss creates a <module-name>.jar.index file containing a list of packages? directories? .... .
- Version slot identifiers are used when you wish to have more than one instance of a module in a module loader under the same name. This may occur when introducing a new major version of a module which is not API-compatible with the old version but is used by newer applications. A version slot identifier is an arbitrary string; thus one can use just about any system they wish for organization. If not otherwise specified, the version slot identifier defaults to "main". When identifying a module in a string, the version slot identifier can be appended to the module name, separated by a colon ":".
- Can modules be hot-(re)deployed?