Requiring JOnAS services in Java EE applications

1.1. Declaring JOnAS service dependencies
1.1.1. Startup of required services
1.1.2. Addition of the manifest attribute during maven build

In some case, Java EE applications you want to execute need specifics JOnAS services to run correctly. If the required services are already started, that means you have defined in the jonas.services property of the JOnAS configuration file the list of the services you want to start, there is no special things to do. But it may be not the case for many reasons. One of them is that you didn't need thoses services before deploying your applications.

Example 1.1. JOnAS service dependency

An application that sends emails needs the JOnAS mail service to retrieve the Session and MimePartDataSource objects.


1.1. Declaring JOnAS service dependencies

To ensure that a set of JOnAS services will be started before deploying a Java EE application, you have to set the Require-JOnAS-Services attribute in the root manifest file of the archive. The value of this property is a comma-separed list of JOnAS service names. Service names must match with the ones defined in the jonas.properties configuration file. In case of an EAR archive, there is no need to modify the manifest files of the embedded JARs, WARs, RARs or CARs archives.

Example 1.2. MANIFEST.MF file content

Manifest-Version: 1.0
...
Require-JOnAS-Services: mail,web


1.1.1. Startup of required services

During the deployment phase of an Java EE archive, the manifest file is analysed to check if the Require-JOnAS-Services property exists. For each declared service, the server verifies wheither the service is already started. If not, two operations should be performed:

  • Install/start bundles for the required service if needed

  • Create configuration for the required service

After that, the service should be started and the application can also be started.

[Note] Note

If the application is undeployed, there is at the moment no ways to specify if these service dependencies should also be stopped or uninstalled.

1.1.2. Addition of the manifest attribute during maven build

The addition of the manifest attribute during a maven build can be automated by configurating the maven plugin like below.

  ...
  <configuration>
    <archive>
      <manifestEntries>
        <Require-JOnAS-Services>service1,service12,..,servicen</Require-JOnAS-Services>
      </manifestEntries>
    </archive>
  </configuration>
  ...

More info may be found here.