J****Boss Enterprise Application Platform Component Details #

https://access.redhat.com/site/articles/112673

Sending Emails #

JBoss AS7 in some conditions can't send emails due to following exception:

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;

This error sometimes appears when mail.jar and activation.jar are not loaded by same classloader. However, this is not the case here.

This is another Jboss AS7 problem: it is necessary to import some addition files from META-INF of mail.jar. Therefore, the javax.activation.api module must have depedencies defined like this:

<module xmlns="urn:jboss:module:1.0" name="javax.activation.api">
<dependencies>
        <module name="javax.api" />
        <module name="javax.mail.api" >
            <imports><include path="META-INF"/></imports>
        </module>
        </dependencies>
    <resources>
        <resource-root path="activation-1.1.1.jar"/>
        <!-- Insert resources here -->
    </resources>
</module>

Our ant unzip task fixes this.

Naming context is read-only #

The problem is that starting from JBoss AS7, the JNDI subsystem should become fully service-oriented, meaning:

  • Contexts are always read-only
  • The NamingStore is populated solely by services
  • When the last binding in a context is removed, the context is automatically removed

The context is read-only, and any call to createSubcontext() fails. Therefore all context has to be set before the portal runs.

Register datasource #

There are several ways how datasource and database jars can be registered in JBoss AS7. This example explains registration of MySql drivers as a module.

Create a module (optionaly) #

Create folder: $jboss_home/modules/com/mysql/jdbc/main and put the mysql connector jdbc drivers there. Add module.xml containing the following:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql.jdbc">
  <resources>
    <resource-root path="mysql-connector-java-5.1.18-bin.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
  </dependencies>
</module>

However, since we already have mysql.jar inside com.liferay.portal module we do not need to create a module but use the existing jar.

Register driver #

The next step is to register driver in the application server configuration file:  $jboss_home/standalone/configuration/standalone.xml. Find the ‘drivers’ element and add a new driver to it:

                <drivers>
                    <driver name="mysql" module="com.liferay.portal">
                        <driver-class>
                            com.mysql.jdbc.Driver
                        </driver-class>
                    </driver>
                    ...

Notice the 'module' attribute. You can put here either the liferay module (as it contains mysql.jar) or the created database driver module (from previous step: com.mysql.jdbc).

Add the datasource #

Final step is to add the datasource. Again, open application server configuration file:  $jboss_home/standalone/configuration/standalone.xml. Find the 'datasources' element and add a new datasource inside:

            <datasources>
                <datasource jndi-name="java_liferay:jdbc/LiferayPool" pool-name="LiferayPool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
                    <connection-url>
                        jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false
                    </connection-url>
                    <driver>
                        mysql
                    </driver>
                    <security>
                        <user-name>
                            root
                        </user-name>
                        <password>
                            password
                        </password>
                    </security>
                </datasource>

Run the server #

If everything is ok, there should be the following output in the log, indicating datasource is registered and binded corectly:

12:38:48,688 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) Bound data source [java:/java_liferay:jdbc/LiferayPool]

That's all;)

Shutdown AS7 from command line #

jboss-admin.bat --connect command=:shutdown

Installing cas-web #

Even default cas.war, built from the source, can not be deployed to the Jboss AS7 without further modifications. Here are the steps how to deploy our cas-web plugin:

  • deploy cas-web. Deployment will fail (Connection cannot be null when 'hibernate.dialect' not set). Stop JBoss server.
  • go to cas web exploded folder: /bundles/jboss-7.0.2/standalone/deployments/cas-web.war
  • Locate: cas-web.war/WEB-INF/lib/cas-server-core-3.3.5.jar. Modify it: remove /META-INF/persistence.xml from it
  • Create WEB-INF/classes/META-INF/persistence.xml with content displayed bellow.
  • Delete cas-web.war/WEB-INF/lib/dom4j-1.6.1.jar
  • Start jboss as7. Wait until everything is up. Trigger deployment of cas-web by creating file: cas-web.war.dodeploy in JBoss standalone deployment folder.

The content of persistence.xml file is:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
        version="2.0">

    <persistence-unit name="CasPersistence" transaction-type="RESOURCE_LOCAL">
          <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
          </properties>
    </persistence-unit>
</persistence>

Note: newer versions of cas.war already has the persistence.xml extracted from the core jar. Moreover, newever persistence.xml contains some additional definitions, be sure not to delete them when adding 'hibernate.dialect' property.

JSF 1.2 in AS 7 #

JBoss AS7 comes with JSF 2.0 implementation. Still, you can enable JSF 1.2 very simply, by adding the following snipped in web.xml:

<context-param>
      <param-name>org.jboss.jbossfaces.JSF_CONFIG_NAME</param-name>
      <param-value>Mojarra-1.2</param-value>
</context-param>

Lastly, application do not need jsf implementation jars or jstl jars, as they are already available by JBoss AS7.

sunjce_provider.jar #

The com.sun.crypto.provider.SunJCE class is part of the <JAVA_HOME>jre/lib/ext directory. In order to scan and load the ext directory we needed to add a MANIFEST.MF to the war file with the following content:

Extension-List: crypto
crypto-Extension-Name: javax.crypto

With that web project scans the ext dir and then finds the sunjce_provider.jar that has a MANIFEST.MF that declares extension. Note that there is a '\n' after javax.crypto!

ClassNotFoundException: com.sun.crypto.provider.SunJCE #

This exception may occur on JBoss AS 7.1.1 and JDK 7. The solution is to edit file:

$JBOSS_HOME/modules/sun/jdk/main/module.xml

and add following lines on appropriate place:

<path name="com/sun/crypto"/>
<path name="com/sun/crypto/provider"/>

This issue should be fixed in Jboss 7.2

Declaring dependencies for Liferay plugins #

JBoss' new classloading mechanism requires each app to declare its dependencies on classes that it requires. JBoss will auto-include some dependencies, but not all, so in some cases you will have to include these dependencies yourself, by including them in the META-INF/MANIFEST.MF file for your Liferay Plugin.

For example, to create a basic servlet in JBoss encapsulated in a JAR file, one must have this in the JAR Manifest file (META-INF/MANIFEST.MF):

Dependencies: javax.api, javax.servlet.api, javax.servlet.jsp.api

If you do not do this, you may get java.lang.NoClassDefFoundError's for common classes like javax.serviet.http.HttpServlet.

JBoss 7.1.3 or Application Platform 6.0.1 #

Latest official JBoss is 7.1.1 (at the time of the writing). However, versions 7.1.2 and 7.1.3 are released, but only through RedHat. You must login to: https://access.redhat.com/jbossnetwork/restricted/listSoftware.html?product=appplatform&downloadType=distributions&eval=true

and download "Application Platform 6.0.1" which is actually JBoss 7.1.3.

Deploying EXT plugins #

When EXT plugin is deployed, portal will put its jar in the portals module folder, located eg here: /modules/com/liferay/portal/main

However, this still does NOT enables the plugin. User have to enabled it in the module.xml file, too, by adding the jar to the list of resources.

Since ext plugin has to be loaded by classloader BEFORE portals classes, user has to put it before any other resource. It seems that resource order in module.xml makes difference for JBoss AS7.

Here is an example of module.xml:

<module xmlns="urn:jboss:module:1.0" name="com.liferay.portal">

    <resources>
        <resource-root path="ext-Batman-ext-service.jar" />
        <resource-root path="hsql.jar" />
        <resource-root path="jtds.jar" />
        <resource-root path="mysql.jar" />
        <resource-root path="portal-service.jar" />
        <resource-root path="portlet.jar" />
    </resources>
    <dependencies>
        <module name="javax.api" />
        <module name="javax.mail.api" />
        <module name="javax.servlet.api" />
        <module name="javax.servlet.jsp.api" />
        <module name="javax.transaction.api" />
    </dependencies>
</module>

What if this doesnt work? #

Since at this moment Im not yet sure that JBoss really takes the order of resources or it was just an acciddent, there should be another solution for loading EXTs.

Idea is to create another JBoss module, eg. ext module, with just ext jars, and make portal module depends on it. THis way ext module classes should be loaded first (hopefully:)

Setting log level #

Open standalone.xml and set the logging level. For example:

    <profile>
        <subsystem xmlns="urn:jboss:domain:logging:1.1">
....
            <logger category="org.quartz">
                <level name="ERROR"/>
            </logger>
...
0 Attachments
30289 Views
Average (1 Vote)
The average rating is 5.0 stars out of 5.
Comments