April 24, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Jumping Into JBoss, Page 2

  • September 3, 2003
  • By Thornton Rose and David Thurmond
  • Send Email »
  • More Articles »

Management

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:

  • Open the management console.
  • Scroll down the page to the "jboss.system" section.
  • Click on the "type=Server" link.
  • Scroll down to "void shutdown()" section.
  • Click the "Invoke" button.

Deploying Applications

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:

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:

22:21:44,730 INFO [MainDeployer] Deployed package: file:/C:/jboss-3.2.1/server/default/deploy/rotmachine.ear

Additionally, if you open the JBoss Management Console, you should see your application listed in the "jboss.j2ee" section.

Undeploying Applications

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:

22:59:41,500 INFO [MainDeployer] Undeployed file:/C:/jboss-3.2.1/server/default/deploy/rotmachine.ear

Data Sources

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:

  1. 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.

  2. Create a data source descriptor for your database, e.g. oracle-ds.xml.

  3. Deploy the data source descriptor as you would deploy an application.

Here is an example of a descriptor for an Oracle data source:

   <?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>

Additional examples of data source descriptors can be found in JBOSS_HOME/docs/examples/jca.

Enterprise JavaBeans (EJBs)

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:

   <?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>

Note that, unlike other J2EE servers, JBoss does not require generation of stubs and skeletons. It handles EJB usage dynamically.

Clients

As mentioned above, JBoss does not require client stubs. You will need to provide only the following to clients:

  • The EJB home and remote.
  • Any classes that are passed between the client and the EJB.
  • A copy of JBOSS_HOME/client/jbossall-client.jar.

Here is an example of connecting to an EJB deployed in JBoss:

   // 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();




Page 2 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel