AnsweredAssumed Answered

How to deploy JNDI references programmatically?

Question asked by kaihuener on Dec 1, 2013
Latest reply on Dec 12, 2013 by frederikheremans1
Hey all,

I recently changed from Tomcat to JBoss application server (version 7.1.1).
According to several documentation (e.g. I adapted
in order to use CDI and JNDI references:
<bean id="transactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:jboss/TransactionManager"></property>
    <property name="resourceRef" value="true" />
<bean id="processEngineConfiguration" class="org.activiti.cdi.CdiJtaProcessEngineConfiguration">
    <property name="dataSourceJndiName" value="java:/jboss/datasources/activiti" />
    <property name="databaseType" value="mysql" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionsExternallyManaged" value="true" />
    <property name="databaseSchemaUpdate" value="true" />

When I try to deploy the bar archive including the new configuration, I get an exception regarding missing initial context:
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

I try to deploy by maven (see e.g. using class
from old
namespace (activiti 5.10). Beside for deployment, I use new (5.14) activiti libs.

I fully understand the exception because outside the JBoss container, there is no initial context with JNDI resources. For example, for unit testing, I use mocked databases in a manually created context to simulate JNDI references. But I have absolutely no idea how to simulate or somehow mock the activiti database and JBoss transaction manager during bar deployment …

Sorry for this lengthy opening– my question: How to programmatically (best case: maven) deploy a bar archive including JNDI references? Is there a way or "good practice" to somehow add a database mock class to the bar archive that is only used during deployment? And how to deal with the JNDI reference for the transaction manager?

Thanks in advance for any ideas,
best regards,