arton / rjb

Ruby Java Bridge
https://www.artonx.org/collabo/backyard/?RubyJavaBridge
GNU Lesser General Public License v2.1
117 stars 34 forks source link

RJB NoClassDefFoundError after loading jar from Rails #36

Closed svhyd closed 9 years ago

svhyd commented 9 years ago

I get a NoClassDefFoundError after loading jar using Rjb:load from Rails but works fine from Ruby IRB terminal. Using IRB, I can load my single jar and there are no complaints from RJB regarding the dependent jars (e.g., Apache Log4j, JFreeCharts etc.)

Rjb:add_jar seems to work from within Rails but there are too many jars to load and irrespective of the order I use to load the jars I get still a NoClassDefFoundError for one or the other the dependency jars (e.g., NoClassDefFoundError (org/apache/log4j/Logger)

It almost seems impossible to get it working from within Rails.

In Rails, I set my classpath in Rjb:load using following but it doesn't seem to work.

classpath = "/my/home/directory/my.jar" + File::PATH_SEPARATOR + Dir.glob("/my/home/directory/lib/*.jar").join(File::PATH_SEPARATOR)

Rjb::load(classpath) # \ THIS HAS NO EFFECT **

So I have to resort to add_jar .. I don't quite understand how is add_jar different from load? And in what circumstances I need to use add_jar instead of load?

arton commented 9 years ago

Hi I'm not sure, but it seems that you had already loaded rjb implicitly. It causes your explicitly call of Rjb::load does not affect. If you set -W (it should set $VERBOSE = true), rjb emits 'Rjb::implicit jvm loading' to $stdout while it was loaded implicitly. I wonder if you could check your loading sequence.

svhyd commented 9 years ago

Hi arton,

I was able to resolve the issue the other day. As you guessed, I was doing Rjb:load twice. We have 2 different jars with 2 different purposes that we use at 2 separate places in the Rails application. I was trying to load the new jar (the 2nd one) all over and that was not taking any effect. By trial and error, I figured it had to do something with the first load, so moved the loading part of both jars to a common/single place and everything was good. You can go ahead and close the issue.

I had another question, do you see Rjb causing memory/performance problems when used in mongrel cluster scenario, is a different instance of JVM launched for each Rjb:load inside of each mongrel Rails application?

Thanks.

arton commented 9 years ago

Hi svhyd Thank you for your follow up report! About mongrel question, I have no idea. However, in theory, JVM in separate processes does not affect each other except for using shared memory or file locks, DB access with row/table locking, also CPU usage.

arton commented 9 years ago

Should I change Rjb::load behavior ? For example, if the jars of the arguments are added, then it calls add_jar implicitly.

arbox commented 8 years ago

@arton Actually some 'reload' functionality could be very useful. Probably require() vs. load() semantics like in Ruby could be implemented. I will document this point in the README tomorrow.

arton commented 8 years ago

Hi arbox, thank you for your opinion. I will investigate after reading your wrote.