Chapter 1. Application Clients

Table of Contents

1.1. Overview
1.2. Programming
1.2.1. Program Architecture
1.2.2. Example
1.3. Deployment Descriptor (DD)
1.3.1. Creating a Deployment Descriptor
1.3.2. Creating a Deployment Descriptor
1.4. Packaging
1.5. Deployment
1.6. Execution
1.6.1. Executing in Console

This chapter discusses application clients that are executed on a separate JVM from the JEUS server (engine container).

1.1. Overview

In general, an application client module running in a JEUS client container is used to call a Java EE application or be provided with Java EE service.

An application client is a stand-alone client that runs in a Java EE environment. It operates within the application client container, which is defined in Java EE Specification. An application client module, a type of JEUS clients, is useful for client/server systems, testing, or debugging.

JEUS application client can use JEUS services, including naming service, scheduler, and security, by using a client container. Without using a client container, parts of Java EE services, like JNDI and security, can be used through the JEUS client library. However, dependency injection and JEUS scheduler cannot be used.

Note

1. For more details about Java EE based application client, refer to Java EE Specifications.

2. For details about JEUS XML schema, refer to "jeus-client-dd.xml" in "JEUS XML Reference."

1.2. Programming

This section describes JEUS client and server architectures, and describes some examples using sample codes.

1.2.1. Program Architecture

An application client is a client program that runs on a JVM that is different from the server.

An application client calls and executes the main() method and runs until the JVM terminates. Like other Java EE application components, an application client also runs in a client container that provides system services, but the container uses less system resources than other Java EE containers. It provides the environment in which Java EE services offered by JEUS can be provided for a general client application.

The services include scheduler, security, JNDI, and other services with which users can use the application components (EJB) and system resources (JDBC data source, JMS connection factory, etc.) that are bound to JEUS via JNDI.

[Figure 1.1] Application Client Architecture

Application Client Architecture Application client architecture


1.2.2. Example

Like other Java programs, an application client must have the main method that is declared in the public class.

The following example is written in Java EE 7 style, and calls EJB via injection. (refer to the ${JEUSHOME}/samples/client/hello/hello-client).

[Example 1.1] <<HelloClient.java>>

package helloejb;

import java.io.*;
import javax.ejb.EJB;

public class HelloClient {
    @EJB(mappedName="helloejb.Hello")
    private static Hello hello;
    
    public static void main(String[] args) {
        System.out.println("EJB output : " + hello.sayHello());
    }
}


Note

Fore details about Java EE application client programming, refer to Java EE 7 Technologies (http://www.oracle.com/technetwork/java/javaee/tech/index-jsp-142185.html).

1.3. Deployment Descriptor (DD)

This section describes how to create a deployment descriptor.

1.3.1. Creating a Deployment Descriptor

A deployment descriptor (hereafter, DD) can be created in the following two ways:

  • Java EE DD

    Java EE Specification defines DD for client modules, and uses standard settings regardless of WAS.

    Java EE 5 and above do not require a standard DD file, and necessary settings can be done through annotations. Therefore, the previous example, [Example 1.1] can be run without any separate application-client.xml file.

    For more information about standard XML descriptor, refer to Java EE Specifications.

  • JEUS DD

    Information about the client module is required for a server to communicate with an application client. DD is an XML document that contains such information.

    DD filename for a client is META-INF\jeus-client-dd.xml. Using a deployment descriptor, a user can decide which services should be provided when deploying each application client to the client container. DD can be modified without changes to the program.

    In general, a deployment descriptor is used to configure a resource used by the client. However, the previous example [Example 1.1] does not require the DD file, thus it is omitted.

Note

For more information about jeus-client-dd.xml, refer to "JEUS XML Reference."

1.3.2. Creating a Deployment Descriptor

If needed for creating a DD, create the jeus-client-dd.xml file before JEUS deploys the client module.

The following example shows an XML file that creates a DD.

Environment variables used by the client, a name to which the EJB application is bound, a name of the bound JDBC datasource, and a JNDI binding name for the JMS queue are specified in the XML file. Except for the environment variables, specify <export-name> as the JNDI name which is actually bound to <ref-name> in the application-client.xml file.

[Example 1.2] <<jeus-client-dd.xml>>

<jeus-client-dd>
    <env>
        <name>year</name>
        <type>java.lang.Integer</type>
        <value>2002</value>
    </env>
    <ejb-ref>
        <jndi-info>
            <ref-name>count</ref-name>
            <export-name>count_bean</export-name>
        </jndi-info>
    </ejb-ref>
    <res-ref>
        <jndi-info>
            <ref-name>datasource</ref-name>
            <export-name>Oracle_DataSource</export-name>
        </jndi-info>
    </res-ref>
    <res-env-ref>
        <jndi-info>
            <ref-name>jms/SalaryInfo</ref-name>
            <export-name>jms/salary_info_queue1</export-name>
        </jndi-info>
    </res-env-ref>
</jeus-client-dd>


Note

For a description of each element in the jeus-client-dd.xml file, refer to "JEUS XML Reference."

1.4. Packaging

Client module packagingmethods are done in two ways, manual packaging and packaging with IDE.

  • Manual Packaging

    If necessary, create a DD XML file by using the XML editor or text editor that is installed on the user's computer. Then gather all the necessary files and create a JAR file for the client module by using the JAR tool provided by Java.

    To package an application client, the application class files, and, in some cases, the application-client.xml and jeus-client-dd.xml files are required.

    Use the jar command to create a JAR file for the client module in the console. By standard, it is possible to specify the main class, which is to be used when executing the JAR file, by using the main-class attribute in the MANIFEST.MF of the JAR file. In such cases, the JEUS client container automatically executes the class.

    The following example shows how to create a JAR file using the jar command.

    jar cvf hello-client.jar *
  • Packaging with IDE

    Create using the IDE tool that supports Java EE environment such as Eclipse, NetBeans, or IntelliJ IDEA. Refer to each IDE's help for details.

1.5. Deployment

An application client module can be deployed "manually" or by using JEUS WebAdmin. In the module, depending on the need, there are the Java EE standard descriptor files, namely the application-client.xml file, and the jeus-client-dd.xml file, which is provided by JEUS. First, create a module file for the application client, and then move the file to a preferred location.

If there is a function that is controlled by the web service client, perform additional deployment via a console tool named jeusadmin or WebAdmin, or use appcompiler to create a web service stub.

Note

1. For how to use WebAdmin, refer to "JEUS WebAdmin Guide".

2. For how to deploy Web service clients, refer to "JEUS Applications & Deployment Guide".

1.6. Execution

This section introduces JEUS libraries that are additionally required by each service and describes how to execute modules in the console.

The following is the list of required JEUS libraries

ServiceJEUS Library
JMS (Java Message Service)
  • SYSTEM_LIB_DIR/jms.jar

Web Service
  • SYSTEM_LIB_DIR/mail.jar

  • SYSTEM_LIB_DIR/jeus-ws.jar

  • JEUS_HOME/lib/shared/wsit-2.3/webservices-rt.jar

  • SYSTEM_LIB_DIR/resolver.jar

JMX (Java Management eXtensions)
  • SYSTEM_LIB_DIR/jmxremote.jar

Note

For more information on web services, refer to "JEUS Web Service Guide".

1.6.1. Executing in Console

To execute an application client module in the console, use appclient. The appclient script is located under the JEUS_HOME\bin directory, and executes an application client module through a client container.

The command line for JEUS client container is as follows:

  • How to use

    appclient -client client_jar_path 
             [-main main_class]
             [-cp classpath] 
             application_arguments...

    The command options are explained in the following table:

    OptionDescription
    -client client_jar_pathSpecifies the path of the application client to be executed.
    [-main main_class]Specifies the main class of the application client. This option is not required when main-class is already specified in the META-INF\MANIFEST.MF, located in the client's class path.
    [-cp classpath]Specifies a class path for executing the client, if needed.
  • Example

    If the example above is executed, the following will be displayed. In order for the application client to be successfully executed, the Hello EJB should be deployed first.

    JEUS_HOME/samples/client/hello/hello-client/dist$ appclient -client hello-client.jar
    [2016.08.03 14:44:46][0] [t-1] [CLIENT-0050] Starting the Application Client Container - JEUS 8
    EJB output : Hello EJB!

    If a user wants to turn of logging, set as follows:

    -Djeus.log.level=OFF

    Note

    For details about log setting, refer to JEUS Server Guide. "Chapter 8. Logging".