Table of Contents
This chapter discusses application clients that are executed on a separate JVM from the JEUS server (engine container).
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, that 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.
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" of "JEUS XML Reference".
This section describes JEUS client and server architectures, and describes some examples using sample codes.
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 JavaEE application components, an application client also runs in a client container that provides system services, but the container uses less system resources than other JavaEE 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 some services that allow users to use the application components (EJB) and system resources (JDBC data source, JMS connection factory, etc.) that are bound to JEUS via JNDI.
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 6 style, and calls EJB via injection. (refer to the JEUSHOME/samples/client/hello example).
[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()); } }
For more information about Java EE application client programming, refer to the Java EE 5 Specification (http://java.sun.com/javaee).
This section describes how to create a deployment descriptor.
Deployment descriptor (hereafter, DD) can be created in the following two ways:
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.
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.
For more information about jeus-client-dd.xml, refer to "JEUS Reference Book".
If needed for creating 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>
For a description of each element in the jeus-client-dd.xml file, refer to "JEUS XML Reference".
Client module packaging methods 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, you need the application class files, and if needed, also include the Application-client.xml and jeus-client-dd.xml files.
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.
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.
1. For how to use WebAdmin, refer to "JEUS WebAdmin Guide".
2. For how to deploy Web service clients, refer to "JEUS Web Service Guide".
This section introduces JEUS libraries which is additionally required by each service, and describes how to execute modules in the console.
To use a web service as an application client, additional libraries are needed and JEUS_HOME/lib/client/clientcontainer.jar needs to be executed. They are located under JEUS_HOME/lib/system(SYSTEM_LIB_DIR). Refer to the following table.
The following is the list of required JEUS libraries
[Table 1.1] JEUS libraries required for each service
Service | JEUS Library |
---|---|
JMS(Java Message Service) | - SYSTEM_LIB_DIR/jms.jar |
Web Service | - SYSTEM_LIB_DIR/jeus-ws.jar - SYSTEM_LIB_DIR/activation.jar - SYSTEM_LIB_DIR/mail.jar - SYSTEM_LIB_DIR/jaxb-impl.jar - SYSTEM_LIB_DIR/saaj-impl.jar - SYSTEM_LIB_DIR/jaxws-rt.jar - SYSTEM_LIB_DIR/sjsxp.jar - SYSTEM_LIB_DIR/streambuffer.jar - SYSTEM_LIB_DIR/stax-ex.jar - SYSTEM_LIB_DIR/resolver.jar - SYSTEM_LIB_DIR/FastInfoset.jar - SYSTEM_LIB_DIR/wsit.jar |
JMX(Java Management eXtensions) | SYSTEM_LIB_DIR/jmxremote.jar |
For more information on web services, refer to "JEUS Web Service Guide".
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:
Option | Description |
---|---|
-client client_jar_path | Specify the path of the application client to be executed. |
[-main main_class] | Specify 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] | Specify 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/samples/client/hello/hello-client/dist$ appclient -client hello-client.jar [2014.05.23 18:00:54][0] [t-1] [CLIENT-0050] Starting the Application Client Container - JEUS 7.0 (Fix#2) EJB output : Hello EJB!
If a user wants to turn of logging, set as follows:
-Djeus.log.level=OFF
For details about log setting, refer to JEUS Server Guide. "Chapter 8. Logging" .