Monday, August 29, 2011

How to deploy my application in an external directory in JBoss-5

If you want to deploy an application outside the "deploy" folder of JBoss in JBossAS-5, you can add your user directory to the ProfileService bootstrap process. This will automatically pick up the specified directory and treat it as if you would put the content to the deploy/ folder. Note that all specified folders need to be fully qualified url.

JBoss AS 5.0.0 EAP
Same as the instructions for JBoss AS 5.1.x below, edit the server/${jboss.server.name}/conf/bootstrap/profile.xml.
JBoss AS 5.1.x
Starting with 5.1.0.Beta1 there have been some changes to the ProfileService. To add your custom folder you would need to edit the server/${jboss.server.name}/conf/bootstrap/profile.xml.


Note - the folder names must be specified using URL syntax. For example, to specify that /home/jpai/test/deploy be used for deployment, the example below uses the value file:///home/jpai/test/deploy.

<bean name="BootstrapProfileFactory"
     class="org.jboss.system.server.profileservice.repository.StaticProfileFactory">
     <property name="bootstrapURI">${jboss.server.home.url}conf/jboss-service.xml</property>
     <property name="deployersURI">${jboss.server.home.url}deployers</property>
     <property name="applicationURIs">
          <list elementClass="java.net.URI">
               <value>${jboss.server.home.url}deploy</value>

               <!-- Add your own deploy folder -->
               <value>file:///home/jpai/test/deploy</value>
          </list>
     </property>
     ...
</bean>


JBoss AS 5.0.x
In JBoss AS 5.0.0.GA you need to edit the %JBOSS_HOME%/server/< serverName>/conf/bootstrap/profile-repository.xml and add your directory to the URIs property of SerializableDeploymentRepositoryFactory bean. Here's an example, where i am adding my /home/jpai/test/deploy folder to the URIs property. Doing so, i will be able to place any deployable application in /home/jpai/test/deploy folder, so that it will be picked up for deployment:

<bean name="SerializableDeploymentRepositoryFactory" 
     class="org.jboss.system.server.profileservice.repository.SerializableDeploymentRepositoryFactory">
      <property name="storeRoot">${jboss.server.base.dir}</property>
      <property name="attachmentsRoot">${jboss.server.data.dir}/attachments</property>
      <property name="applicationURIs">
         <array elementClass="java.net.URI">
            <value>${jboss.server.home.url}deploy</value>
           
              <!-- Add my own folder -->
            <value>file:/home/jpai/test/deploy</value>
     ...
</bean>

JBoss AS 5.x Architecture

2.4. What is new in JBoss AS 5?

  • New kernel ⇒ JBoss Microcontainer
    • is a refactoring of old JMX Microkernel (JBoss AS 3.x and 4.x)
    • the core of JBoss AS 5
  • New messaging provider ⇒ JBoss Messaging
    • Replaces old JBossMQ (shipped with JBoss AS 4.x series)
  • One of the first application servers to implement EJB 3.0 specification (dating back to 4.x series)
  • Reliable transaction manager ⇒ JBoss TS
    • more than 20 years of expertise in transaction management
  • JBoss Web based on Apache Tomcat 6.0
  • JBoss WS 3.0 (support for JAX-WS/JAX-RPC)
    • can be replaced by Sun Metro or Apache CXF for example
  • Two new configurations:
    • standard: Java EE compliant configuration.
    • web: provides support for JTA/JCA and JPA in addition to the Servlet/JSP container. The server can only be accessed through the http port.

2.5. JBoss AS Architecture

"JBoss AS is assembled from a set of independent, yet cooperating components and services that are neatly packaged and fully hot-deployable. It is architected to be seamlessly embeddable in applications, and the nature of its embedding is completely customizable to the requirements of the application itself. Only the critical and necessary application server components, therefore, need to be brought along as part of the application’s baseline footprint. Developers can also easily create and add their own services to the system, thus ensuring that custom services exhibit the same consistent behavior as the JBoss standard set of services."

2.6. JBoss Microcontainer Layer

JBoss Microcontainer is an inversion of control (IoC) framework. IoC frameworks let you create, configure and wire up simple Java objects (POJOs). Classes don’t need special coding to be usable. The objects created usualy represent the modules of your application.
  • Replaces JMX-based Microkernel, though still supports all JMX Microkernel features
  • IoC framework similar to Spring IoC
  • POJO based kernel (no need for Standard/XMBean or MBeanProxy)
  • Simplified and improved lifecycle management
  • Additional control over dependencies
  • Transparent AOP integration
  • Virtual File System (VFS)
  • Virtual Deployment Framework
  • OSGi class-loading

2.7. Services Layer

  • Service-oriented architecture - service is either defined as a POJO or a JMX Managed Bean (use the JMX kernel, still available in JBoss 5.x but is created by JBoss Microcontainer).
  • Services are hot-pluggable
  • Makes it possible to tune the system for just the required services to lower the overall footprint (easier to secure and tune)
  • Easy to define new services and package them as SARs (service archives) or JARs (Java ARchives)
  • Examples: Servlet/JSP container, EJB container, transaction management, messaging, connection pooling, security etc.

2.8. Aspect Layer

Increase the modularity of an application by allowing the separation of cross-cutting concerns (e.g logging is often required in many parts of your application).
  • Based on aspect-oriented programming model (AOP)
  • Defines cross-cutting simple-to-use services
  • Makes it possible to add object persistence, caching, replication, remoteness, security, etc. late in the development cycle by annotating existing plain-old-java-objects (a.k.a POJOs) 

2.9. Application Layer

  • This is where Java EE applications reside
  • This layer deals with the business logic while leaving the container services up to JBoss AS
  • Portable - Independent of JBoss AS

2.10. JBoss AS Services

  • JBoss Microcontainer - POJOs services container
  • JBoss Microkernel - JMX MBean server (One of the primary POJOs created by JBoss Microcontainer)
  • Aspect-oriented Framework
  • Web Application Services - based on Tomcat (Servlet, JSP, JSF)
  • Enterprise Services: EJB, ORB, JNDI, JTA
  • Web Services - based on SOAP, WSDL, UDDI, and XML
  • Messaging Services: JMS, JDBC, JCA
  • Persistence Services - Hibernate O/R mapping and transparent persistence
  • HA Services: clustering, fail-over, load-balancing, distributed deployments
  • Security Services - based on JAAS
  • Console Services - monitoring, configuration, deployment, management, lifecycle


Thursday, August 18, 2011

Configuring a datasource for Oracle DB

To make the JDBC driver classes available to JBoss Application Server, copy the archive ojdbc5.jar to the lib directory in the default server configuration (assuming that is the server configuration you’re running).
Then create a text file in the deploy directory called oracle-ds.xml with the following datasource descriptor :

Install JDBC Drivers


For the JBoss Application Server and our applications to use the external database, we also need to install the database's JDBC driver. The JDBC driver is a JAR file, which you'll need to copy into your JBoss AS's <JBoss_Home>/server/all/lib directory. Replace all with the server configuration you are using if needed. This file is loaded when JBoss starts up. So if you have the JBoss AS running, you'll need to shut down and restart. The availability of JDBC drivers for different databases are as follows.


Creating a DataSource for the External Database

JBoss AS connects to relational databases via datasources. These datasource definitions can be found in the <JBoss_Home>/server/all/deploy directory. The datasource definitions are deployable just like WAR and EAR files. The datasource files can be recognized by looking for the XML files that end in *-ds.xml.