JRuby and Sqlite3

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

JRuby and Sqlite3

Alex jimmy Montaño fuentes
Hi,
I want to compile my ruby application into a jar File.

Now there I get a strange error using jdbc/sqlite3.

This is my ruby (test) code:

require 'rubygems'
require 'jdbc/sqlite3'
require 'java'

import org.sqlite.JDBC

connection = java.sql.DriverManager.getConnection
'jdbc:sqlite:test.sqlite3'
begin
  statement = connection.createStatement
  begin
    statement.executeUpdate("insert into user values ('test', 7)")
    rs = statement.executeQuery("select * from user")
    begin
      puts "user\tpass"
      while rs.next
        puts ["#{rs.getString(1)}",
              "#{rs.getString(2)}"].join("\t")
      end
    ensure
      rs.close
    end
  ensure
    statement.close
  end
ensure
  connection.close
end

There are no problems using jruby directly, but when I include the
script in jruby-complete.jar using "jar ufe myapp.jar
org.jruby.JarBootstrapMain jar-bootstrap.rb", I always get an error when
I start it ( java -jar myapp.jar ):

NameError: missing class or uppercase package name (`org.sqlite.JDBC')

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: JRuby and Sqlite3

Ariel Valentin
Does your jar contain all of the dependencies? Or are they located somewhere else?

Thanks,
Ariel
---
Sent from my mobile device. Please excuse any errors.

> On Feb 28, 2015, at 10:05 AM, Roderich T. <[hidden email]> wrote:
>
> Hi,
> I want to compile my ruby application into a jar File.
>
> Now there I get a strange error using jdbc/sqlite3.
>
> This is my ruby (test) code:
>
> require 'rubygems'
> require 'jdbc/sqlite3'
> require 'java'
>
> import org.sqlite.JDBC
>
> connection = java.sql.DriverManager.getConnection
> 'jdbc:sqlite:test.sqlite3'
> begin
>  statement = connection.createStatement
>  begin
>    statement.executeUpdate("insert into user values ('test', 7)")
>    rs = statement.executeQuery("select * from user")
>    begin
>      puts "user\tpass"
>      while rs.next
>        puts ["#{rs.getString(1)}",
>              "#{rs.getString(2)}"].join("\t")
>      end
>    ensure
>      rs.close
>    end
>  ensure
>    statement.close
>  end
> ensure
>  connection.close
> end
>
> There are no problems using jruby directly, but when I include the
> script in jruby-complete.jar using "jar ufe myapp.jar
> org.jruby.JarBootstrapMain jar-bootstrap.rb", I always get an error when
> I start it ( java -jar myapp.jar ):
>
> NameError: missing class or uppercase package name (`org.sqlite.JDBC')
>
> --
> Posted via http://www.ruby-forum.com/.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: JRuby and Sqlite3

Alex jimmy Montaño fuentes
In reply to this post by Alex jimmy Montaño fuentes
The jar file is a raw "jruby-complete.jar" containing no dependencies.

All necessary gem files are located in a subfolder "gems" with the
ENV['GEM_PATH'] variable pointing on it.

Thanks,
Roderich

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: JRuby and Sqlite3

Karol Bucek

require 'jdbc/sqlite3' does not auto-load the driver class: https://github.com/jruby/activerecord-jdbc-adapter/tree/master/jdbc-sqlite3

On Sat, Feb 28, 2015 at 4:27 PM, Roderich T. <[hidden email]> wrote:
The jar file is a raw "jruby-complete.jar" containing no dependencies.

All necessary gem files are located in a subfolder "gems" with the
ENV['GEM_PATH'] variable pointing on it.

Thanks,
Roderich

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: JRuby and Sqlite3

Alex jimmy Montaño fuentes
In reply to this post by Alex jimmy Montaño fuentes
@Karol: thanks for your hint.

But the problem still exists. I downloaded the sqlite-jdbc.jar. I put in
in my classpath AND included it in my myapp.jar file.

But the result is:
DBI::DatabaseError: java.sql.SQLException: No suitable driver found

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: JRuby and Sqlite3

Alex jimmy Montaño fuentes
In reply to this post by Alex jimmy Montaño fuentes
Problem solved!

I made a mistake by including sqlite-jdbc into the main jar file.

Thanks to all!

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: JRuby and Sqlite3

Alex jimmy Montaño fuentes
In reply to this post by Alex jimmy Montaño fuentes
Forgive my ignorance, but I'm new to JRuby. What is the reason for
requiring "rubygems", I don't see any specific code that uses a gem.

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: JRuby and Sqlite3

Tim Uckun
rubygems allows you to be able to require the other libs in your script.  Basically it tells your script which directories to load your libs from.

These days people mostly use bundler though.

On Fri, Apr 10, 2015 at 4:24 PM, Cloudrck Tech <[hidden email]> wrote:
Forgive my ignorance, but I'm new to JRuby. What is the reason for
requiring "rubygems", I don't see any specific code that uses a gem.

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: JRuby and Sqlite3

Christian MICHON
you still need to call rubygems before you call bundler anyway...

On Fri, Apr 10, 2015 at 6:26 AM, Tim Uckun <[hidden email]> wrote:
rubygems allows you to be able to require the other libs in your script.  Basically it tells your script which directories to load your libs from.

These days people mostly use bundler though.

On Fri, Apr 10, 2015 at 4:24 PM, Cloudrck Tech <[hidden email]> wrote:
Forgive my ignorance, but I'm new to JRuby. What is the reason for
requiring "rubygems", I don't see any specific code that uses a gem.

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email






--
Christian
Reply | Threaded
Open this post in threaded view
|

Re: JRuby and Sqlite3

christian
in newer ruby version including jruby there is no need to require "rubygems" it is already required.

if you do not want rubygems from a jruby commandline execution then you need to explicitly tell jruby not to require it:

jruby -Xcli.rubygems.enable=false -e "p require 'rubygems'"

-christian


On Fri, Apr 10, 2015 at 11:36 AM, Christian MICHON <[hidden email]> wrote:
you still need to call rubygems before you call bundler anyway...

On Fri, Apr 10, 2015 at 6:26 AM, Tim Uckun <[hidden email]> wrote:
rubygems allows you to be able to require the other libs in your script.  Basically it tells your script which directories to load your libs from.

These days people mostly use bundler though.

On Fri, Apr 10, 2015 at 4:24 PM, Cloudrck Tech <[hidden email]> wrote:
Forgive my ignorance, but I'm new to JRuby. What is the reason for
requiring "rubygems", I don't see any specific code that uses a gem.

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email






--
Christian