xruby and external .jar libraries

7 views
Skip to first unread message

prhlava

unread,
Dec 5, 2007, 2:52:59 PM12/5/07
to xruby-devel

Hello!

I am curious, if I have a .jar library file in the CLASSPATH, will
xruby import a class from it or only the standard java libraries (the
ones comming with jvm) are supported?

I would like to try netcdf java library from xruby.

So far, the import does not give error if loading x.y.* but gives
error when loading x.y.ClassName (x,y is the java package where the
ClassName is). The .jar is defined in CLASSPATH shell variable. All of
this is under linux.

Should this work?

Vlad

sishen

unread,
Dec 5, 2007, 2:59:52 PM12/5/07
to xruby...@googlegroups.com
I can't quite catch you..

xruby is used to translate ruby source to java bytecode. Where should you to import a class from ruby?

Or you can just use xruby to generate a jar file and then working with that file, i think.

Xue Yong Zhi

unread,
Dec 5, 2007, 3:04:53 PM12/5/07
to xruby...@googlegroups.com
Xruby does support Java Integration, you can check the docs at: http://code.google.com/p/xruby/wiki/JavaIntegration
 
But unfortunetely we do not have anyone working on the Java Integration at this moment. So the team may not be able to fix the issue promotly.
 
Unlike other ruby 3rd party implementation teams, xruby has no full time developer and has least available resource. Right now we are focusing on the compiler and Java Integration is laggging behind.


Date: Thu, 6 Dec 2007 03:59:52 +0800
From: yedin...@gmail.com
To: xruby...@googlegroups.com
Subject: [xruby-devel] Re: xruby and external .jar libraries

prhlava

unread,
Dec 5, 2007, 3:09:38 PM12/5/07
to xruby-devel
> I can't quite catch you..

(under bash)
export CLASSPATH=/usr/share/java/netcdf-2.2.22.jar

ruby script (lets call it .ncf.rb):

import 'ucar.nc2.NetcdfFile' # <- this fails, but the
netcdf-2.2.22.jar contains NetcdfFile.class in the ucar/nc2 path);

f = NetcdfFile.open('/home/vladimir/tmp/download/ecmwf/output01.nc')

# eof

if I run:

java -jar ~/app/xruby/xruby-0.3.2.jar netcdf-xruby.rb

i get:

Exception in thread "main" Couldn't find class ucar.nc2.NetcdfFile

Basially, I am trying to load java class (in xruby script) from .jar
file.

Vlad

prhlava

unread,
Dec 5, 2007, 3:13:46 PM12/5/07
to xruby-devel
> Xruby does support Java Integration, you can check the docs at:http://code.google.com/p/xruby/wiki/JavaIntegration

Thanks, that is my source of info.

> But unfortunetely we do not have anyone working on the Java Integration at this moment. So the team may not be able to fix the issue promotly.

I am just having a bit of spare time and playing with xruby, so this
is not a big deal.

> Unlike other ruby 3rd party implementation teams, xruby has no full time developer and has least available resource. Right now we are focusing on the compiler and Java Integration is laggging behind.
I understand this, sorry if I sounded winging...

Vlad

Xue Yong Zhi

unread,
Dec 5, 2007, 3:18:40 PM12/5/07
to xruby...@googlegroups.com

> I understand this, sorry if I sounded winging...
>
> Vlad

Hey Vlad,

You are very welcome to report issues:) I am sorry as we may not be able to fix it in a timely manner.


Get the power of Windows + Web with the new Windows Live. Power up!

prhlava

unread,
Dec 5, 2007, 3:19:26 PM12/5/07
to xruby-devel
> ruby script (lets call it .ncf.rb):

should be: ncf.rb

> java -jar ~/app/xruby/xruby-0.3.2.jar netcdf-xruby.rb

should be: java -jar ~/app/xruby/xruby-0.3.2.jar ncf.rb

sishen

unread,
Dec 5, 2007, 3:44:17 PM12/5/07
to xruby...@googlegroups.com
Hi, prhlava.

If you need to work with the external jar package, you shouldn't use "java -jar" because it will default discard the classpath information you provided and use the default classpath specified in MANIFEST.MF.

Try the below two ways:

1. compile the rb file first, then run the app
    1 java -jar xruby-0.3.2.jar -c netcdf-xruby.rb
    2. java -cp xruby-0.3.2.jar:netcdf-xruby.jar xruby.netcdf-xruby.main

2. run the xruby with classpath
    1. java -cp xruby-0.3.2.jar:netcdf-2.2.22.jar com.xruby.Main netcdf-xruby.rb

prhlava

unread,
Dec 5, 2007, 3:57:38 PM12/5/07
to xruby-devel
> Try the below two ways:
>
> 1. compile the rb file first, then run the app
> 1 java -jar xruby-0.3.2.jar -c netcdf-xruby.rb
> 2. java -cp xruby-0.3.2.jar:netcdf-xruby.jar xruby.netcdf-xruby.main
>
> 2. run the xruby with classpath
> 1. java -cp xruby-0.3.2.jar:netcdf-2.2.22.jar com.xruby.Main
> netcdf-xruby.rb
>

:-) Thank you very much, both ways work.

Vlad
Reply all
Reply to author
Forward
0 new messages