Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

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

Closed
iuwei opened this issue Apr 12, 2011 · 2 comments
Closed

Comments

@iuwei
Copy link

iuwei commented Apr 12, 2011

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
Copy link
Owner

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
Copy link
Author

iuwei commented Apr 13, 2011

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

@iuwei iuwei closed this as completed Apr 13, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants