# CLASSPATH problem?

**URL:** <https://www.ruby-forum.com/t/classpath-problem/144747>\
**Category:** Ruby\
**Created:** [August 1, 2008, 6:26pm UTC](https://www.ruby-forum.com/t/classpath-problem/144747 "2008-08-01T18:26:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [August 1, 2008, 6:26pm UTC](https://www.ruby-forum.com/t/classpath-problem/144747/1 "2008-08-01T18:26:06Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [August 2, 2008, 12:21am UTC](https://www.ruby-forum.com/t/classpath-problem/144747/2 "2008-08-02T00:21:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [August 18, 2008, 8:10am UTC](https://www.ruby-forum.com/t/classpath-problem/144747/3 "2008-08-18T08:10:58Z")

</div>

Charles Oliver N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
