2 Replies Last post: Feb 1, 2013 4:04 AM by Robert Buck  
Robert Buck Newbie 3 posts since
Sep 13, 2012
Currently Being Moderated

Jan 29, 2013 8:03 PM

How does one debug a jruby project that has an embedded jar?

So what I would like to do is debug a jruby project that contains a Jar. But no matter what I do I cannot seem to be able to do this. Despite all attempts, the jar does not seem to be loaded, or the classloader is not finding the classes because it is associated to a different classloader? Unsure.

 

But anyways, this is bone stock sort of stuff, here is a promintent Github project that illustrates the issue:

 

https://github.com/jruby/activerecord-jdbc-adapter

 

Namely, open the activerecord-jdbc-adapter-master/jdbc-mysql directory as a project, add the lib directory to the project path, add a simple test such as:

 

require 'rubygems'
require 'jdbc/mysql'
require 'java'

 

puts "enumerating..."
java.sql.DriverManager.getDrivers.each{ |e| puts e }

 

url = "jdbc:mysql://localhost/test"
connection = java.sql.DriverManager.getConnection url

 

You will frequently run into one of two classes of errors:

 

1. no such file to load -- jdbc/mysql

2. DriverManager.java:602:in `getConnection': java.sql.SQLException: No suitable driver found for jdbc:...

 

If someone could provide a specific example of debugging a ruby gem that has a JAR file located in the lib directory, a tested working example, I'd appreciate it. At this point I have not found any way to make either RubyMine or IntelliJ+Ruby-Plugin work.

Lei Gao Newbie 8 posts since
Jan 19, 2013
Currently Being Moderated
Feb 1, 2013 3:26 AM in response to: Robert Buck
Re: How does one debug a jruby project that has an embedded jar?

Maybe I am not clear about what you ask. Here is the way I setup my classpath, I put a initializer there containing the following code

 

jars_folder = Dir.pwd + "/lib/jars"

 

Dir.entries(jars_folder).each do |jar_file|

  if RUBY_PLATFORM =~ /java/

    $CLASSPATH << (jars_folder + File::SEPARATOR + jar_file) if (/\.jar$/ =~ jar_file.to_s)

  end

end

 

 

and I put all my jar files under 'lib/jars'. Of course, I put my jdbc driver under the lib/jars folder too.

 

Lei

More Like This

  • Retrieving data ...