Theapp-client
quickstart demonstrates how to code and package a client app and use the {productName} client container to start the clientMain
program.
The app-client
quickstart demonstrates how to use the {productName} client container to start the client Main
program and provide Dependency Injections (DI) for client applications in {productNameFull}. It also shows you how to use Maven to package the application according to the Java EE specification.
This example consists of the following Maven projects, each with a shared parent.
Project | Description |
---|---|
|
This project contains the EJB code that can be called by the client. |
|
This project contains a simple client application that runs in the application-client container to show the injection. |
|
This project builds the EAR artifact and pulls in the EJB and client artifacts. |
The root pom.xml
file builds each of the subprojects in the appropriate order.
This example shows how to invoke an EJB from a remote standalone application on the same machine. Both the client and server are on the same machine, so the defaults are sufficient and no authentication is necessary.
-
Verify that the quickstart deployed successfully as described above.
-
Navigate to the root directory of this quickstart and type the following command to run the application. Make sure you replace
{jbossHomeName}
with the path to your {productName} installation.$ {jbossHomeName}/bin/appclient.sh ear/target/app-client.ear#simpleClient.jar Hello from command line
NoteFor Windows, use the {jbossHomeName}\bin\appclient.bat
script. -
Review the result. The client outputs the following information, which is provided by the server application.
[org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-51) Main started with arguments [org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-51) [Hello, from, command, line] [org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-##) Hello from StatelessSessionBean@myhost
The client output shows that the
ServerApplication
is called at the jboss.nodemyhost
. The application client connected automatically a server on the same machine. -
Review the server log files to see the bean invocations on the server.
ClientContext is here = {Client =dev84, jboss.source-address=localhost/127.0.0.1:45315}
This example shows how to invoke an EJB from a remote standalone Java EE application on a different machine. In this case, the client needs to define a properties file to define properties to connect and authenticate to the server. The properties file is passed on the command line using the --ejb-client-properties
argument.
-
Install {productName} on this machine.
-
Add the authorized application and management users to the {productName} server on this machine as described above.
-
Start the {productName} server with the following command, replacing
MACHINE_1_IP_ADDRESS
with the IP address of this machine. These arguments make the server accessible to the network.$ {jbossHomeName}/bin/standalone.sh -b MACHINE_1_IP_ADDRESS -bmanagement MACHINE_1_IP_ADDRESS
NoteFor Windows, use the {jbossHomeName}\bin\standalone.bat
script.
-
Install {productName} on this server. There is no need to add the application users to this server.
-
Download the
app-client
quickstart to this machine. -
Create a
jboss-ejb-client.properties
file. This file can be located anywhere in the file system, but for ease of demonstration, we create it in the root directory of this quickstart. Add the following content, replacingMACHINE_1_IP_ADDRESS
with the IP address ofMachine_1
.remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false remote.connections=default remote.connection.default.host=MACHINE_1_IP_ADDRESS remote.connection.default.port=8080 remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false remote.connection.default.username=quickstartUser remote.connection.default.password=quickstartPwd1!
-
Open a terminal and navigate to the root directory of the quickstart.
-
Deploy the
app-client
quickstart to the remote machine using the following command. Make sure you replaceMACHINE_1_IP_ADDRESS
with the IP address ofMachine_1
.$ mvn clean install wildfly:deploy -Dwildfly.hostname=MACHINE_1_IP_ADDRESS [-Dwildfly.port=9099] -Dwildfly.username=quickstartAdmin -Dwildfly.password=adminPwd1!
-
Verify that the quickstart deployed successfully and the server is running on
Machine_1
as described above. -
Type the following command to run the
app-client
application.$ {jbossHomeName}/bin/appclient.sh --ejb-client-properties=ejb-client.properties ear/target/app-client.ear#simpleClient.jar Hello from command
NoteFor Windows, use the {jbossHomeName}\bin\appclient.bat
script. -
Review the result. The client outputs the following information, which was provided by the application.
[org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-51) Main started with arguments [org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-51) [Hello, from, command, line] [org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-##) Hello from StatelessSessionBean@theOtherHOST
The client output shows that the
ServerApplication
is called at the jboss.nodetheOtherHOST
. -
Review the server log files on the remote machine to see the bean invocations on the server.
ClientContext is here = {Client =dev84, jboss.source-address=localhost/127.0.0.1:45315}
As shown above, the connected servers can be configured using the properties file. It is also possible to connect multiple servers or a cluster using the same
jboss-ejb-client.properties
file.
Follow these instructions if you are testing the quickstart on the same machine.
-
Make sure you have started the {productName} server on the machine where the quickstart is deployed as described above.
-
Open a terminal on that server and navigate to the root directory of this quickstart.
-
When you are finished testing, type this command to undeploy the archive from the local machine.
$ mvn wildfly:undeploy
Follow these instructions if you are testing the quickstart on a different machine.
-
Make sure you have started the {productName} server on the remote server machine,
Machine_1
, where the quickstart is deployed as described above. -
Open a terminal on the local client machine,
Machine_2
, and navigate to the root directory of this quickstart. -
When you are finished testing, type this command to undeploy the archive from the remote server machine,
Machine_1
.$ mvn wildfly:undeploy -Dwildfly.hostname=MACHINE_1_IP_ADDRESS [-Dwildfly.port=9099] -Dwildfly.username=quickstartAdmin -Dwildfly.password=adminPwd1!