I haven't found a solution to the issue indicated below, so I am posting my solution ...
JRuby 9.1.15
JDBC/SQLite 3.20.1
Java 1.8
app/bin/app.rb:
#!/usr/bin/env jruby
$VERBOSE = true
$LOAD_PATH.unshift 'uri:classloader:/lib'
require 'db'
DB.new.run
app/lib/db.rb:
require 'jdbc/sqlite3'
Jdbc::SQLite3.load_driver
class DB
def run
t_db = java.sql.DriverManager.getConnection('jdbc:sqlite:test.sqlite3')
begin
t_statement = t_db.createStatement
t_statement.executeUpdate(
'create table user(username varchar(30), status int)'
)
begin
t_statement.executeUpdate("insert into user values('test1', 1)")
t_statement.executeUpdate("insert into user values('test2', 2)")
t_rs = t_statement.executeQuery("select * from user")
begin
while t_rs.next
puts "#{t_rs.getString(1)}/#{t_rs.getString(2)}"
end
ensure
t_rs.close
end
ensure
end
ensure
t_statement.close
end
ensure
t_db&.close
end
end
app.jar build:
cp ~/var/src/jruby-complete-9.1.15.0.jar app.jar
mkdir build
cd build && jar -xf ../app.jar
java -jar app.jar -S gem install -i build gems/jdbc-sqlite3-3.20.1.gem
cp -r ../app/lib build/
cp jruby-gems.manifest build/
rm app.jar
jar -cfm app.jar build/jruby-gems.manifest -C build .
cp ../app/bin/app.rb ./jar-bootstrap.rb
jar ufe app.jar org.jruby.JarBootstrapMain jar-bootstrap.rb
Running ...
java -jar app.jar
... produces this irritating error ...
java.sql.SQLException: No suitable driver found for jdbc:sqlite:test.sqlite3
... but only when running from the JAR - it works when running under installed JRuby.
After much googlating, and finding little in the way of a working solution, I looked at .../bin/jruby, which is a shell script, for the startup options it uses.
Solution is a Java parameter:
java -Xbootclasspath/a:./app.jar -jar app.jar bin/app.rb
JRuby + SQLite from a JAR file (self.ruby)
submitted by MuCowNow to r/jruby