CLASSPATH problem?

today I’ve switch from jruby-1.1.RC3 to jruby-1.1.3

I’m using to jdbc connectors, installed by gem :
jdbc-mysql-5.0.4
jdbc-sqlite3-3.5.8

I’ve set my CLASSPATH to :
export
CLASSPATH=".:/opt/jruby-1.1.3/lib/ruby/gems/1.8/gems/jdbc-sqlite3-3.5.8/
lib/sqlite-3.5.8.jar:/opt/jruby-1.1.3/lib/ruby/gems/1.8/gems/jdbc-mysql-
5.0.4/lib/mysql-connector-java-5.0.4-bin.jar"

If i echo the “–classpath” of /opt/jruby-1.1.3/bin/jruby, i get :

From jruby : -classpath =
/opt/jruby/lib/bsf.jar:/opt/jruby/lib/jruby.jar:/opt/jruby/lib/profile.j
ar:.:/opt/jruby-1.1.3/lib/ruby/gems/1.8/gems/jdbc-sqlite3-3.5.8/lib/sqli
te-3.5.8.jar:/opt/jruby-1.1.3/lib/ruby/gems/1.8/gems/jdbc-mysql-5.0.4/li
b/mysql-connector-java-5.0.4-bin.jar

seems OK

but with :
require ‘java’
require ‘rubygems’
require ‘jdbc/sqlite3’
module JavaLang
include_package “java.lang”
end

module JavaSql
include_package ‘java.sql’
end

puts “ENV[‘CLASSPATH’] = #{ENV[‘CLASSPATH’]}”

begin
JavaLang::Class.forName(“org.sqlite.JDBC”).newInstance
[…]
rescue JavaLang::ClassNotFoundException
puts “ClassNotFoundException”
rescue JavaSql::SQLException
puts “SQLException”
end

i get allways “ClassNotFoundException”

I’ve even verified (jar tf /path/to/file.jar) the Class
“org.sqlite.JDBC” is in.

also reading “sqlite3.rb” gives :

$ cat
/opt/jruby-1.1.3/lib/ruby/gems/1.8/gems/jdbc-sqlite3-3.5.8/lib/jdbc/sqli
te3.rb
module Jdbc
module SQLite3
VERSION = “3.5.8”
end
end
if RUBY_PLATFORM =~ /java/
require “sqlite-#{Jdbc::SQLite3::VERSION}.jar”
else
warn “jdbc-SQLite3 is only for use with JRuby”
end%

is the latest require “sqlite-#{Jdbc::SQLite3::VERSION}.jar” usefull ?

it seems, to me, it has no effect…

Une Bévue wrote:

i get allways “ClassNotFoundException”
The problem here is the Class.forName call. Class.forName will try to
use the system classloader if nothing else is specified. Since the
system classloader doesn’t allow pulling in new JAR files after startup,
we have a separate sub-classloader for JRuby.

If you want to load the class, just reference it directly or try to
import it.

require ‘jdbc/sqlite3’
org.sqlite.JDBC # or import ‘org.sqlite.JDBC’

This will use the JRuby classloader which knows about the loaded JAR
file. I tried this, and it works fine for me here.

âž” jruby -e “require ‘rubygems’; require ‘jdbc/sqlite3’; p
org.sqlite.JDBC”
Java::OrgSqlite::JDBC

  • Charlie

Charles Oliver N. [email protected] wrote:

This will use the JRuby classloader which knows about the loaded JAR
file. I tried this, and it works fine for me here.

? jruby -e “require ‘rubygems’; require ‘jdbc/sqlite3’; p org.sqlite.JDBC”
Java::OrgSqlite::JDBC

OK, I’ll try that, but, if i remember well, the same script was working
with 1.1.RC3 and not with 1.1.3.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs