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.
Please sign in to leave a comment.
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
Thanks, let me try that Lei.
What I find strange is that the pattern used in the mentioned project does not work. Even by itself, without a debugger, none of the activerecord-jdbc code works at all for me, because of this:
The code fails. Let me try our own driver the way you suggest.