Search code examples
log4jactivemq-classicmule-studio

JMSAppender with MuleStudio


I'm trying to do a proof of concept in MuleStudio 3.5.0 that requires JMSAppender for Log4j using ActiveMQ.

I've added the following to my log4j.xml file:

<appender name="jms" class="org.apache.log4j.net.JMSAppender">
  <param name="InitialContextFactoryName" value="org.apache.activemq.jndi.ActiveMQInitialContextFactory" />
  <param name="ProviderURL" value="tcp://localhost:61616" />
  <param name="TopicBindingName" value="logTopic" />
  <param name="TopicConnectionFactoryBindingName" value="ConnectionFactory" />
</appender>

<root>
  <appender-ref ref="jms"/>
</root>

I've added the following to my pom:

<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>activemq-core</artifactId>
  <version>5.7.0</version>
</dependency>

However, when I build and run it, I get the following ClassNotFound exception on startup:

log4j: Class name: [org.apache.log4j.net.JMSAppender]
log4j: Setting property [initialContextFactoryName] to [org.apache.activemq.jndi.ActiveMQInitialContextFactory].
log4j: Setting property [providerURL] to [tcp://localhost:61616].
log4j: Setting property [topicBindingName] to [logTopic].
log4j: Setting property [topicConnectionFactoryBindingName] to [ConnectionFactory].
log4j: Getting initial context.
log4j:ERROR Error while activating options for appender named [jms].
  javax.naming.NoInitialContextException: Cannot instantiate class:  org.apache.activemq.jndi.ActiveMQInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.activemq.jndi.ActiveMQInitialContextFactory]
  at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
  at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)

I'm not sure where to go from here. Some search hits say "you'll need a jndi.properties file"...but I don't know what that means.

Can someone provide step-by-step instructions on what I need to do to get this to work?


Solution

  • The solution is to add the activemq-core library to mule/boot directory for the Mule Server being used by MuleStudio, e.g.: C:\MuleStudio\plugins\org.mule.tooling.server.3.4.1.ee_3.4.1.201312062152\mule\boot

    The gotcha in my case was that, while the About box showed MuleStudio at Version 3.5.0, clicking on mule-project.xml showed that studio was actually using 3.4.1 as the server.