### jBPM5 on AS7: Lightning !

Most of you probably know that JBoss Application Server 7 has recently been released in the community. Due to its lightweight and modular approach, concurrency and much more, the startup time has descreased significantly, which is always nice to hear for developers! Although I still have to figure out how to get a cup of coffee in only 3 seconds now 😉

During my holiday break, I took some time to play with it, and see how difficult it would be to get jBPM5 running on AS7. It took me some time, but in the end I managed to get the jBPM console running on AS7. I’ll describe the steps I took to get there now, but we’ll try to get this integrated in the installer in the near future, so other people can start playing with this stuff more easily as well (any volunteers?).

I started with downloading JBossAS 7.0.0.Final and took the jBPM 5.1.0.Final jbpm console wars as a starting point.

• Biggest change probably is the fact that as7 ships with JPA2 and hibernate4, while jBPM is still using JPA1 and hibernate3. Due to it’s modular design, we can however still run hibernate3 applications on as7, we just need to add these dependencies ourselves now (and exclude hibernate4).
• Add the following jars from the jBPM runtime to the WEB-INF/lib folder of the server war: hibernate-core, hibernate-entitymanager, hibernate-commons-annotations, hibernate-annotations, dom4j, javassist
• Make sure to exclude the hibernate4 jars, by adding the following WEB-INF/jboss-deployment-structure.xml in the server war:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"><deployment>  <exclusions>    <module name="org.hibernate"/>  </exclusions><deployment></jboss-deployment-structure>

• I got an error with my persistence.xml and JPA2 so I disabled JPA2 scanning by commenting out the JPA module (org.jboss.as.jpa) and subsystem (urn:jboss:domain:jpa:1.0) in the standalone.xml configuration file.

• Data sources are no longer specified by dropping a *ds.xml in the deploy folder but as part of the configuration. In configuration/standalone.xml, add the following datasource:
<datasource enabled="true" context="true" name="java:jboss/datasources/jbpmDS"><connection-url>jdbc:h2:tcp://localhost/~/test</connection-url><driver>h2</driver><pool></pool><security>  <user-name>sa</user-name>  <password></password></security><validation></validation><timeout></timeout><statement></statement></datasource>

Notice that we also changed the jndi name of the datasource as we need to use one of the known domains (jboss in this case). This means you also need to change the name of the datasource in your persistence.xml.

• The security configuration is also different, you should now add a security domain in the standalone.xml and copy the users.properties and roles.properties file in the WEB-INF/classes folder:
<security-domain name="jbpm-console" cache-type="default"><authentication>  <login-module code="UsersRoles" flag="required"/></authentication></security-domain>

• Add your database driver (in our case h2.jar) to WEB-INF/lib of the server war.
• The default transaction manager lookup no longer works (as its jndi name has changed) so I registered a custom transaction manager lookup
<property name="hibernate.transaction.manager_lookup_class"       value="org.jbpm.JBPMTransactionManager" />
package org.jbpm;import java.util.Properties;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.transaction.Transaction;import javax.transaction.TransactionManager;import org.hibernate.HibernateException;import org.hibernate.transaction.TransactionManagerLookup;public class JBPMTransactionManager implements TransactionManagerLookup {public Object getTransactionIdentifier(Transaction transaction) {  return transaction;}public TransactionManager getTransactionManager(Properties properties) throws HibernateException {  try {    return (TransactionManager) new InitialContext()      .lookup("java:jboss/TransactionManager");  } catch (NamingException e) {    throw new RuntimeException(e);  }}public String getUserTransactionName() {  return null;}}
if("text".equals(mediaType.getType()) && "plain".equals(mediaType.getSubtype()))