Forum: JRuby in `require': no such file found --mysql(Load Error)

Posted by Anbu Sivakani (anbusivakani)
on 2010-03-03 09:21
Hi friends ...

             I am using netbeans IDE for JRuby. While trying for MySQL
connection am getting the load error. How to rectify this?
Posted by Charles Nutter (headius)
on 2010-03-03 14:39
(Received via mailing list)
If you are trying to use the MySQL native gem for MRI on JRuby, that
will never work. The "mysql" library plugs directly into MRI using C
APIs.

You may be interested in using JDBC instead, which can provide access
to MySQL (and other databases) without any native libraries (and works
fine from JRuby as well:
http://rubylearning.com/blog/2007/05/05/connect-jruby-to-mysql-using-jdbc/

(FYI) just import the java.sql classes used in that example directly;
the include_package stuff he uses is *not* the recommended way.

On Wed, Mar 3, 2010 at 2:21 AM, Anbu Sivakani <lists@ruby-forum.com> 
wrote:
>    http://xircles.codehaus.org/manage_email
>
>
>

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

    http://xircles.codehaus.org/manage_email
Posted by Eric Christopherson (Guest)
on 2010-03-04 00:34
(Received via mailing list)
On Wed, Mar 3, 2010 at 7:38 AM, Charles Oliver Nutter
<headius@headius.com> wrote:
> the include_package stuff he uses is *not* the recommended way.
Is there anything for JRuby that allows you to read embedded MySQL
databases (i.e. without a server)? I know for Java there's mysql-je,
so I could probably use that, if nothing else.

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

    http://xircles.codehaus.org/manage_email
Posted by Charles Nutter (headius)
on 2010-03-04 01:18
(Received via mailing list)
On Wed, Mar 3, 2010 at 5:34 PM, Eric Christopherson
<echristopherson@gmail.com> wrote:
> Is there anything for JRuby that allows you to read embedded MySQL
> databases (i.e. without a server)? I know for Java there's mysql-je,
> so I could probably use that, if nothing else.

I had never even heard of mysql-je. If it has to be an embedded
*mysql* database, that's probably your best bet.

If it just needs to be an embedded database, there's lots of other
options, like Derby (JavaDB), HSQLDB, and even sqlite3.

- Charlie

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

    http://xircles.codehaus.org/manage_email
Posted by Eric Christopherson (Guest)
on 2010-03-04 02:07
(Received via mailing list)
OK, thanks.

Playing around with the JDBC example there, I can't seem to make it
work unless I actually put the jar file in my CLASSPATH. I see some
messages saying old versions of JRuby didn't support setting the class
path via command line arguments; is that still true in 1.4.0?

On Wed, Mar 3, 2010 at 6:17 PM, Charles Oliver Nutter
<headius@headius.com> wrote:
> options, like Derby (JavaDB), HSQLDB, and even sqlite3.
>
> - Charlie
>
> ---------------------------------------------------------------------
> 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
Posted by Charles Nutter (headius)
on 2010-03-04 02:19
(Received via mailing list)
On Wed, Mar 3, 2010 at 7:07 PM, Eric Christopherson
<echristopherson@gmail.com> wrote:
> Playing around with the JDBC example there, I can't seem to make it
> work unless I actually put the jar file in my CLASSPATH. I see some
> messages saying old versions of JRuby didn't support setting the class
> path via command line arguments; is that still true in 1.4.0?

JRuby 1.4 and higher should work fine using either the CLASSPATH env
var or the -cp JVM argument (as -J-cp when passed to JRuby, of
course).

So the example there didn't work if you required the jar directly in the 
script?

- Charlie

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

    http://xircles.codehaus.org/manage_email
Posted by Eric Christopherson (Guest)
on 2010-03-04 02:39
(Received via mailing list)
On Wed, Mar 3, 2010 at 7:18 PM, Charles Oliver Nutter
<headius@headius.com> wrote:
>
> So the example there didn't work if you required the jar directly in the script?

Ah... if I require the whole pathname of the jar, and then try
importing classes, that works. However, if I don't require the jar,
the -J-cp argument doesn't help:

H:\Projects\Scripts>jruby -J-cp "C:\Documents and
Settings\echristopherson\My
Documents\Development\Java\mysql-connector-java-3.1.10\mysql-connector-java-3.1.10-bin.jar"
jdbc.rb
:1: C:\Documents and Settings\echristopherson\My
Documents\Development\Java\mysql-connector-java-3.1.10\mysql-connector-java-3.1.10-bin.jar:1:
\3Invalid char `\3' ('♥') in expression (SyntaxError)

-- I understand it's trying to treat the jar as a Ruby script because
I put a space after -J-cp, but I don't think there should be a '\3'
before 'Invalid char `\3''.

I took out the space after -J-cp:

H:\Projects\Scripts>jruby -J-cp"C:\Documents and
Settings\echristopherson\My
Documents\Development\Java\mysql-connector-java-3.1.10\mysql-connector-java-3.1.10-bin.jar"
jdbc.rb
(eval):1:in `include_class': cannot load Java class
com.mysql.jdbc.Driver (NameError)

It does work if I set CLASSPATH right. It also works if I use a
pathname without spaces. Would there be any way to make it accommodate
spaces?

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

    http://xircles.codehaus.org/manage_email
Posted by Eric Christopherson (Guest)
on 2010-03-04 02:40
(Received via mailing list)
On Wed, Mar 3, 2010 at 7:38 PM, Eric Christopherson
<echristopherson@gmail.com> wrote:
>> var or the -cp JVM argument (as -J-cp when passed to JRuby, of
> Documents\Development\Java\mysql-connector-java-3.1.10\mysql-connector-java-3.1.10-bin.jar"
>
>
Sorry; I spoke too soon about it working. I forgot I still had the
hard-coded jar path in the script itself. I still get a NameError even
if the jar path doesn't have spaces.

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

    http://xircles.codehaus.org/manage_email
Posted by Jon Forums (jonm)
on 2010-03-04 15:22
(Received via mailing list)
> > Is there anything for JRuby that allows you to read embedded MySQL
> > databases (i.e. without a server)? I know for Java there's mysql-je,
> > so I could probably use that, if nothing else.
> 
> I had never even heard of mysql-je. If it has to be an embedded
> *mysql* database, that's probably your best bet.
> 
> If it just needs to be an embedded database, there's lots of other
> options, like Derby (JavaDB), HSQLDB, and even sqlite3.
> 

http://www.h2database.com/html/main.html is also nice.

Jon

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

    http://xircles.codehaus.org/manage_email
Posted by Charles Nutter (headius)
on 2010-03-05 15:57
(Received via mailing list)
On Wed, Mar 3, 2010 at 7:38 PM, Eric Christopherson
<echristopherson@gmail.com> wrote:
> It does work if I set CLASSPATH right. It also works if I use a
> pathname without spaces. Would there be any way to make it accommodate
> spaces?

This looks like a bug in how we process -J-cp argument to JRuby. It
should take the quoted string en masse as the element to add to
classpath. Can you file a bug for that?

On UNIX, it appears to work ok:

~/projects/jruby âž” mkdir "path with spaces"

~/projects/jruby âž” cp ~/Downloads/junit-4.6.jar "path with spaces"/

~/projects/jruby âž” jruby -J-cp "path with spaces/junit-4.6.jar" -rjava
-e "p org.junit.Test"
Java::OrgJunit::Test

- Charlie

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

    http://xircles.codehaus.org/manage_email
Posted by Eric Christopherson (Guest)
on 2010-03-06 00:23
(Received via mailing list)
On Fri, Mar 5, 2010 at 8:56 AM, Charles Oliver Nutter
<headius@headius.com> wrote:
> On Wed, Mar 3, 2010 at 7:38 PM, Eric Christopherson
> <echristopherson@gmail.com> wrote:
>> It does work if I set CLASSPATH right. It also works if I use a
>> pathname without spaces. Would there be any way to make it accommodate
>> spaces?
>
> This looks like a bug in how we process -J-cp argument to JRuby. It
> should take the quoted string en masse as the element to add to
> classpath. Can you file a bug for that?

I will do so. Have you confirmed that it fails in 1.5 too?

It does turn out, though, that spaces aren't necessarily the problem
-- I was actually unable to successfully use -J-cp at all under
Windows. I had a "false positive" when it seemed to work but I had
CLASSPATH set.

> On UNIX, it appears to work ok:
>
> ~/projects/jruby âž” mkdir "path with spaces"
>
> ~/projects/jruby âž” cp ~/Downloads/junit-4.6.jar "path with spaces"/
>
> ~/projects/jruby âž” jruby -J-cp "path with spaces/junit-4.6.jar" -rjava
> -e "p org.junit.Test"
> Java::OrgJunit::Test

Yes, this works on OS X.

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

    http://xircles.codehaus.org/manage_email
Posted by Eric Christopherson (Guest)
on 2010-03-06 04:57
(Received via mailing list)
On Fri, Mar 5, 2010 at 5:23 PM, Eric Christopherson
<echristopherson@gmail.com> wrote:
> On Fri, Mar 5, 2010 at 8:56 AM, Charles Oliver Nutter
>> This looks like a bug in how we process -J-cp argument to JRuby. It
>> should take the quoted string en masse as the element to add to
>> classpath. Can you file a bug for that?
>
> I will do so. Have you confirmed that it fails in 1.5 too?

Sorry, never mind. Jruby 1.5 does handle it correctly.

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

    http://xircles.codehaus.org/manage_email
Posted by Vladimir Sizikov (Guest)
on 2010-03-06 08:56
(Received via mailing list)
Hi Eric,

On Sat, Mar 6, 2010 at 4:57 AM, Eric Christopherson
<echristopherson@gmail.com> wrote:
> On Fri, Mar 5, 2010 at 5:23 PM, Eric Christopherson
> <echristopherson@gmail.com> wrote:
>> On Fri, Mar 5, 2010 at 8:56 AM, Charles Oliver Nutter
>>> This looks like a bug in how we process -J-cp argument to JRuby. It
>>> should take the quoted string en masse as the element to add to
>>> classpath. Can you file a bug for that?
>>
>> I will do so. Have you confirmed that it fails in 1.5 too?
>
> Sorry, never mind. Jruby 1.5 does handle it correctly.

Yes, there was a bug in the native launcher which we fixed in 1.5.dev.
There we so much work on the native launchers since 1.4, so it is
definitely worth at least trying 1.5.0.dev.

Thanks,
   --Vladimir

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

    http://xircles.codehaus.org/manage_email
Posted by Charles Nutter (headius)
on 2010-03-07 14:09
(Received via mailing list)
On Sat, Mar 6, 2010 at 1:56 AM, Vladimir Sizikov <vsizikov@gmail.com> 
wrote:
> On Sat, Mar 6, 2010 at 4:57 AM, Eric Christopherson
> <echristopherson@gmail.com> wrote:
>> Sorry, never mind. Jruby 1.5 does handle it correctly.
>
> Yes, there was a bug in the native launcher which we fixed in 1.5.dev.
> There we so much work on the native launchers since 1.4, so it is
> definitely worth at least trying 1.5.0.dev.

Ok, my bad, I should have suggested trying 1.5 first :)

- Charlie

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

    http://xircles.codehaus.org/manage_email
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.