Data Source
If your application will connect to the database, you may need to configure a data source for the database. The following describes how to configure a simple Data source:
If the JDBC driver of the database you are using is not in the lib directory of the server, copy the driver to this directory and restart JBoss.
Create a data source description file for your database, for example, oracle-ds.xml:
Deploy the data source description file in the same way as deploying an application.
The following is an example of a description file for the oracle Data source:
& Lt? Xml version = "1.0" encoding = "UTF-8 "? & Gt
& Lt datasources & gt
& Lt local-tx-datasource & gt
& Lt jndi-name & gtOracleDS & lt/jndi-name & gt
& Lt connection-url & gtjdbc: oracle: thin :@ serverip: 1521: DB & lt/connection-url & gt
& Lt driver-class & gtoracle. jdbc. driver. OracleDriver & lt/driver-class & gt
& Lt user-name & gtdev & lt/user-name & gt
& Lt password & gtsecret & lt/password & gt
& Lt/local-tx-datasource & gt
& Lt/datasources & gt
Examples of other data source description files can be found in JBOSS_HOME/docs/examples/jca.
EJB
Creating ejbs for JBoss is the same as any other J2EE application server, but an additional JBoss EJB deployment description file jboss. xml is required. The following is an example:
& Lt? Xml version = "1.0" encoding = "UTF-8 "? & Gt
& Lt! DOCTYPE jboss PUBLIC "-// JBoss // dtd jboss // EN"
Http://www.jboss.org/j2ee/dtd/jboss.dtd & gt
& Lt jboss & gt
& Lt enterprise-beans & gt
& Lt session & gt
& Lt ejb-name & gtProcessor & lt/ejb-name & gt
& Lt jndi-name & gtejb/Processor & lt/jndi-name & gt
& Lt/session & gt
& Lt entity & gt
& Lt ejb-name & gtData & lt/ejb-name & gt
& Lt jndi-name & gtejb/Data & lt/jndi-name & gt
& Lt/entity & gt
& Lt/enterprise-beans & gt
& Lt/jboss & gt
Note that, unlike other J2EE servers, JBoss does not need to generate stubs and skeletons, which can dynamically call ejbs.
Client
As mentioned above, JBoss does not require a client stub (stubs). You only need to provide the following interfaces to the client:
UEJB Home interface and Remote interface;
U any objects transmitted between the client and EJB;
U a copy of The JBOSS_HOME/client/jbossall-client.jar file.
The following is an example of connecting ejbs deployed in JBoss:
// Create an environment:
Hashtable env = new Hashtable ();
Env. put ("java. naming. factory. initial ",
"Org. jnp. interfaces. NamingContextFactory ");
Env. put ("java. naming. factory. url. pkgs ",
"Org. jboss. naming: org. jnp. interfaces ");
Env. put ("java. naming. provider. url", "localhost ");
// Create name context:
InitialContext context = new InitialContext (env );
// Find the Home interface:
CipherHome home = (CipherHome) context. lookup ("ejb/org/rotmachine/Cipher ");
// Obtain the Remote interface:
Cipher cipher = home. create ();
A sample application
To help you better understand JBoss, this article contains an application named RotMachine. For more information, see the resource link.
RotMachine is a simple J2EE application, including an EJB (Stateless SessionBean), a Web client, and a Command-line client. It uses the project template of JBoss, and you may need some additional development tools mentioned above.
To compile the RotMachine source file, extract the file to a specified directory. In Windows:
U opens a command prompt window;
U type: cd? (Decompress the Directory );
U type: ant deploy-server.
In Unix:
U open a Shell;
U type: cd? (Decompress the Directory );
U type: ant deploy-server.
To test RotMachine on the command line client, in Windows:
U opens a command prompt window;
U type: cd buildin;
U type: run-client.
In Unix:
U open a Shell;
U type: cd build/bin;
U type:./run-client.sh.
To test RotMachine on the Web Client, open a browser and enter "http: // localhost: 8080/rotmachine/index. jsp, enter some text in the form, and click Go!" Button.