http://www.developer.com/open/article.php/3071661/Jumping-Into-JBoss.htm
JBoss is a free, open source, application server that implements the complete
Java 2 Enterprise Edition (J2EE) stack, including Java Server Pages (JSP),
servlets, and Enterprise JavaBeans (EJB). For J2EE developers that are getting
started with JBoss, this article presents the basics, including downloading,
installation, application deployment, and data source configuration. To run JBoss, you will need the following tools: Additionally, to develop applications for JBoss, you may want the following
tools: To get JBoss, go to www.jboss.org. JBoss
is available there in two flavors: the standard bundle, which includes Jetty for
web pages and servlets, and the Tomcat bundle, which includes (you guessed it)
Tomcat instead of Jetty. As of this writing, JBoss 3.2.1 is the latest stable release. To install JBoss, first unzip the distribution file to a directory of your
choice. A directory named JBoss-version should be created, and it should
contain the following directories: Second, set the following environment variables: JBoss comes with three server configurations: minimal - This configuration includes only logging, the JNDI service,
and the URL deployment scanner. You would want to use this configuration
for starting services that don't require J2EE or as the base for a custom
configuration. default - This configuration is the default. It includes all of the
J2EE services exception RMI/IIOP and clustering. all - This configuration includes all JBoss services. To start JBoss: Windows:
Unix:
If JBoss starts successfully, you should see something like this: Once the server is started successfully, you can verify that all of the J2EE
services are up and running by opening http://localhost:8080/jmx-console/ in
your browser. The JBoss Management Console will start. It shows all of the
services included in the currently running JBoss configuration and various
details about each service. JBoss can also run as an NT Service or a Unix service. For more information
on how to do either, see the "JBoss 3.0 Quick Start Guide". If you started JBoss in the foreground from an MS-DOS Prompt window, Command
Prompt window, or Unix shell, simply press Ctrl-C in the window where JBoss
is running.
To shutdown JBoss in the window or shell where it is running, press Ctrl-C.
To shutdown JBoss from another window or shell: Windows:
Unix:
Jboss is managed with a web-based console. To access it, start your browser
and go to "http://localhost:8080/jmx-console". To view or change the
configuration for a particular service, simply click on the link to it. Additionally, with the management console, you can invoke public methods
of services. For example, to shutdown the server: Deploying applications to JBoss could not be easier. Simply copy your
application archive file -- .jar, .war, or .ear -- to the deploy directory of
the server configuration that is running. JBoss will detect the file, extract
the contents, and load the application. Here is an example of deploying an application to the default server
configuration: Windows: Unix: During deployment, JBoss logs messages to the console and log/server.log,
which is located in the server configuration directory. If deployment is
successful, you should see a message like this: Additionally, if you open the JBoss Management Console, you should see your
application listed in the "jboss.j2ee" section. Undeploying applications is even easier than deploying them. To undeploy a
application, delete the application archive file from the deploy directory.
JBoss will notice that the file has been deleted and undeploy the application.
When undeploying an application, JBoss logs messages to the console and
server.log. If undeployment is successful, you should see a message like this:
If your application is going to connect to a database using JBoss, you will
need to configure a data source for the database. Here is how to configure a
basic data source: If the JDBC driver library for your database is not in lib directory of
the server configuration you are using, copy it there, then restart JBoss.
Create a data source descriptor for your database, e.g.
oracle-ds.xml. Deploy the data source descriptor as you would deploy an
application. Here is an example of a descriptor for an Oracle data source: Additional examples of data source descriptors can be found in
JBOSS_HOME/docs/examples/jca. EJBs are constructed for JBoss like they would be constructed for any other
J2EE application server, with the addition of a JBoss EJB deployment descriptor,
jboss.xml. Here is an example: Note that, unlike other J2EE servers, JBoss does not require generation of
stubs and skeletons. It handles EJB usage dynamically. As mentioned above, JBoss does not require client stubs. You will need to
provide only the following to clients: Here is an example of connecting to an EJB deployed in JBoss: To help you further investigate JBoss, an example application called
RotMachine is included with this article. See the Resources
section below for a link. RotMachine is a simple J2EE application that includes an EJB (stateless
session bean), a web client, and a command-line client. It was built using the
JBoss project template, so you will want to get the additional tools listed in
the Tools section above. To install the RotMachine source, unzip the archive file to a directory of
your choice. To build and deploy RotMachine: Windows:
Unix:
To test RotMachine using the command-line client: Windows:
Unix:
To test RotMachine using the web client:
Jumping Into JBoss
September 3, 2003
Tools
Downloading
Installation
Server Configurations
Startup
21:11:16,637 INFO [Server] JBoss (MX MicroKernel) [3.2.1 (build: CVSTag=JBoss_3
_2_1 date=200305041533)] Started in 26s:919ms
Shutdown
Management
Deploying Applications
copy rotmachine.ear %JBOSS_HOME%\server\default\deploy
cp rotmachine.ear $JBOSS_HOME/server/default/deploy22:21:44,730 INFO [MainDeployer] Deployed package:
file:/C:/jboss-3.2.1/server/default/deploy/rotmachine.ear
Undeploying Applications
22:59:41,500 INFO [MainDeployer] Undeployed
file:/C:/jboss-3.2.1/server/default/deploy/rotmachine.ear
Data Sources
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@oracle.somewhere.com:1521:DB</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>dev</user-name>
<password>secret</password>
</local-tx-datasource>
</datasources>
Enterprise JavaBeans (EJBs)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS//EN"
"http://www.jboss.org/j2ee/dtd/jboss.dtd">
<jboss>
<enterprise-beans>
<session>
<ejb-name>Processor</ejb-name>
<jndi-name>ejb/Processor</jndi-name>
</session>
<entity>
<ejb-name>Data</ejb-name>
<jndi-name>ejb/Data</jndi-name>
</entity>
</enterprise-beans>
</jboss>
Clients
// Create env.
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 naming context.
InitialContext context = new InitialContext(env);
// Find home.
CipherHome home = (CipherHome) context.lookup("ejb/org/rotmachine/Cipher");
// Create remote.
Cipher cipher = home.create();
Example Application
Resources