Embedded JBoss

From Shrubbery

Jump to: navigation, search


Notes on using Embedded JBoss (the one based on JBoss AS 5).

Contents

Starting Embedded JBoss

See the Embedded JBoss (wiki)

Jars

When using the Seam 2.x distribution, the following jars should be in the classpath:

  • lib/jboss-embedded-api.jar
  • lib/test/hibernate-all.jar
  • lib/test/jboss-embedded-all.jar
  • lib/test/thirdparty-all.jar

When using the Embedded JBoss distribution, the following jars should be in the classpath (basically all the jars in the 'lib' directory of the Embedded JBoss distribution):

  • lib/hibernate-all.jar
  • lib/jboss-embedded-all.jar
  • lib/jboss-embedded-tomcat-bootstrap.jar
  • lib/jboss-embedded.jar
  • lib/thirdparty-all.jar

Classpath

The classpath should be in the following order:

  1. The bootstrap directory
  2. The Embedded JBoss jars.
  3. Application code - EJB jars, etc.
  4. Overrides for third party jars.
  5. The catch all 'thirdparty-all.jar' library.

Using Java 6

Add the following when using Sun JDK 6:

-Dsun.lang.ClassLoader.allowArraySyntax=true

See http://seamframework.org/Documentation/DoesSeamWorkWithJDK60

Maven Repository

Maven dependency information for the Embedded JBoss jars:

            <dependency>
                <groupId>org.jboss.embedded</groupId>
                <artifactId>jboss-embedded-all</artifactId>
                <version>${version.jboss-embedded}</version>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.jboss.embedded</groupId>
                        <artifactId>jboss-embedded</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.jboss.microcontainer</groupId>
                        <artifactId>jboss-deployers-client-spi</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.jboss.microcontainer</groupId>
                        <artifactId>jboss-deployers-core-spi</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.jboss.embedded</groupId>
                <artifactId>jboss-embedded</artifactId>
                <version>${version.jboss-embedded}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.embedded</groupId>
                <artifactId>thirdparty-all</artifactId>
                <version>${version.jboss-embedded}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.embedded</groupId>
                <artifactId>hibernate-all</artifactId>
                <version>${version.jboss-embedded}</version>
                <scope>test</scope>
            </dependency>

The property version.jboss-embedded can be defined as:

    <properties>
        <version.jboss-embedded>beta3.SP12</version.jboss-embedded>
    </properties>

Note that these dependencies are in test scope, which means they will be available for compiling unit tests. Other libraries will be required to compile Java Enterprise code if this is the case.

Another alternative is to remove the <scope> and use the Embedded JBoss jars to compile against. While this can be more convenient, the application code may develop some unwanted dependencies on the Embedded JBoss libraries.

JMS Configuration

The new embedded JBoss uses the same configuration files as JBoss 5.x. JMS is configured in hsqldb-persistence-service.xml, and this can be adjusted to work with other databases using the examples shown here.

NOTE: Embedded JBoss beta3.SP5 uses JBoss Messaging 1.4.0.SP1 - Download the JBM 1.4.0.SP1 distribution and use the examples as a basis for your own configuration. Using configuration examples from other versions of JBM will not work.

Embedded JBoss Tests in Maven

The surefire plugin can be configured to put the bootstrap directory. In this example the bootstrap files are in etc/bootstrap and Java 6 is being used:

           <plugin>
               <artifactId>maven-surefire-plugin</artifactId>
               <configuration>
                   <additionalClasspathElements>
                       <additionalClasspathElement>etc/bootstrap</additionalClasspathElement>
                   </additionalClasspathElements>
                   <systemProperties>
                       <property>
                           <name>sun.lang.ClassLoader.allowArraySyntax</name>
                           <value>true</value>
                       </property>
                   </systemProperties>
               </configuration>
           </plugin>

Troubleshooting

Warnings you may see, and what to do about them...

Log4j not initialized properly

Put log4j.xml in the source tree, or otherwise in your classpath.

WARN - You should use the 2.0 version of the Microcontainer xml

Change the namespace and schema location of the <deployment> element so it looks like this:

<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
            xmlns="urn:jboss:bean-deployer:2.0">

FATAL - {persistence unit name} JTA

This can be ignored. It's a bad log message in the Hibernate EJB module. Maybe it can be eliminated by upgrading the Hibernate3 jars?

NPEs and "No such method" errors in Bootstrap.getInstance().bootstrap()

Embedded JBoss will throw all kinds of strange exceptions if the classpath isn't correct. For example:

  • AbstractKernelController - Error installing to PreInstall: name=JNDIBasedSecurityManagement state=Real
    java.lang.reflect.MalformedParameterizedTypeException
  • NullPointerException or "No such method"

This is usually caused by something incorrect in the classpath.

  • Make sure there are no jars from older versions of JBoss in the classpath before the embedded JBoss jars. For example: jboss-system.jar, javassist.jar, jboss-jmx.jar, etc.
  • Make sure the bootstrap directory is present in the classpath.
  • When using IDEA, put the embedded JBoss jars first in the classpath, even before any module dependencies.
    • It's okay to have thirdparty-all.jar last. You will need to do this if you use newer versions of commons-collections, etc.
    • Hibernate jars can also be before hibernate-all.jar. You will need to do this if you use a newer version of Hibernate.

Here is an example classpath:

    • First: jdk, bootstrap directory
    • Hibernate - hibernate.jar
    • Embedded JBoss - hibernate-all.jar, jboss-embedded-all.jar, jboss-embedded.jar
    • Module sources
    • Module dependencies
    • Other libraries (e.g. Seam, JBoss stuff)
    • Last: thirdparty-all.jar

JBoss Messaging warnings about transaction isolation level

Solution - Edit the data source definition and add:

<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>

Unable to create a KernelInitializer based on the specified KernelConfig

Usually this is because the third party jar dependencies are not in the classpath. The simplest solution is to add thirdparty-all.jar to the classpath.

ConcurrentModificationException during deployment

Occasionally, Embedded JBoss will throw a ConcurrentModificationException when deploying an application using one of the 'deployResourceBases', or any other 'wildcard' deployment methods.

Several workarounds have been proposed, but as of E-JBoss beta3.SP5 the following do not work:

  • Retrying deployment when an exception is thrown - Bootstrap bombs the second time. It looks like there is some stuff that gets set up but never destroyed.
  • Using the EmbeddedBootstrap code from Seam - Nope. Same thing... dies about every third time.
Here is a link to the forum topic.

Josh's Notes on using Embedded JBoss

I was using the Embedded EJB3 that came with Seam 1.2.x for the main project at work for some time, and I thought that maybe it would be good to upgrade to the new Embedded JBoss while upgrading to Seam 2.0. After getting most of that working I found that Embedded JBoss has a bootstrap/deployment issue that prevents it from working properly 100% of the time. When the container bootstraps and deploys it sometimes throws a ConcurrentModificationException.

In any case, I reverted back to Embedded EJB3 and live with that until the issue is resolved. Other than that I found that having the same deployment descriptors and application packaging for both embedded and standalone JBoss was very convenient.

Building from sources

After checking out the Embedded JBoss tag from JBoss SVN it can be built from sources using:

  1. cd {checkout dir}/build
  2. export JAVA_HOME=/path/to/java5
  3. ./build.sh (this will build JBoss AS, download dependent libraries, etc.)
  4. cd ../embedded
  5. ./build.sh (this will build the Embedded JBoss jars)

Links

Personal tools