reidmorrison / jruby-jms

Complete JRuby API into Java Messaging Specification (JMS)
Apache License 2.0
47 stars 21 forks source link

Could not initialize class org.apache.activemq.ActiveMQPrefetchPolicy #6

Closed iuwei closed 13 years ago

iuwei commented 13 years ago

HI: I'm working with Windows 7 activemq-5.4.2 Jruby 1.6.0 Rails 3.0.4

When i run this code

require 'rubygems'
require 'jms'

Connect to ActiveMQ

config = {
  :factory => 'org.apache.activemq.ActiveMQConnectionFactory',
  :broker_url => 'tcp://localhost:61616',
  :require_jars => ["D:/Develop/Servers/apache-activemq-5.4.2/activemq-all-5.4.2.jar"]
}

JMS::Connection.session(config) do |session|
  session.producer(:queue_name => 'ExampleQueue') do |producer|
    producer.send(session.message("Hello World"))
  end
end

I got this error:

NativeException in MobileController#welcome java.lang.NoClassDefFoundError: Could not initialize class org.apache.activemq.ActiveMQPrefetchPolicy

Started GET "/" for 127.0.0.1 at Tue Apr 12 19:18:21 +0800 2011 Processing by MobileController#welcome as HTML Loading Jar File:D:/Develop/Servers/apache-activemq-5.4.2/activemq-all-5.4.2.jar Completed in 30ms

NativeException (java.lang.NoClassDefFoundError: Could not initialize class org.apache.activemq.ActiveMQPrefetchPolicy): app/controllers/mobile_controller.rb:15:in `welcome'

Rendered D:/Program Files/jruby-1.6.0/lib/ruby/gems/1.8/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/_trace.erb (5.0ms) Rendered D:/Program Files/jruby-1.6.0/lib/ruby/gems/1.8/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (147.0ms) Rendered D:/Program Files/jruby-1.6.0/lib/ruby/gems/1.8/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (162.0ms)

reidmorrison commented 13 years ago

We saw a similar error when we upgraded to ActiveMQ V5.5.0. ActiveMQ 5.5.0 requires additional jar files now for its new logging framework.

The following example works with 5.5.0:

require 'rubygems'
require 'jms'

# Connect to ActiveMQ
config = {
  :factory => 'org.apache.activemq.ActiveMQConnectionFactory',
  :broker_url => 'tcp://localhost:61616',
  :require_jars => [
    "~/Applications/apache-activemq-5.5.0/activemq-all-5.5.0.jar",
    "~/Applications/apache-activemq-5.5.0/lib/optional/slf4j-log4j12-1.5.11.jar",
    "~/Applications/apache-activemq-5.5.0/lib/optional/log4j-1.2.14.jar"
  ]
}

JMS::Connection.session(config) do |session|
  session.producer(:queue_name => 'ExampleQueue') do |producer|
    producer.send(session.message("Hello World"))
  end
end

The following example works on Mac and Linux using ActiveMQ 5.4.2:

require 'rubygems'
require 'jms'

# Connect to ActiveMQ
config = {
  :factory => 'org.apache.activemq.ActiveMQConnectionFactory',
  :broker_url => 'tcp://localhost:61616',
  :require_jars => [
    "~/Applications/apache-activemq-5.4.2/activemq-all-5.4.2.jar"
  ]
}

JMS::Connection.session(config) do |session|
  session.producer(:queue_name => 'ExampleQueue') do |producer|
    producer.send(session.message("Hello World"))
  end
end

Otherwise it could be a Windows specific issue with ActiveMQ, or check that the path to the jar file is valid. I would suggest by starting to run the above examples stand-alone outside of rails to help isolate the issue.

iuwei commented 13 years ago

When i restart my box, this error vanished. Thanks for your fast response :)