[R] rJava classpath issues

Munir, Danish danish.munir at lehman.com
Fri Jun 13 00:09:08 CEST 2008


I'm having some issues with getting my own jars to work properly with
rJava.
Bear with me as I explain my scenario:

I have a java package called rjbridge, with the following classes:
RJBridge.class
ObjectInfo.class
....
....

Each of the classes has the following line on top: package com.rjbridge

My directory structure is:

/home/Danish/java/com/rjbridge
All the class files lie in the above directory
I use the following commands to compile and jar:

cd /home/Danish/java
javac -d . ./com/rjbridge/*.java
jar -cvf rjbridge.jar ./com/rjbridge

So far, so good. Everything works as it should, and I can use the
RJBridge class as follows:
java -cp /home/Danish/java/rjbridge.jar RJBridge [args]

and it runs fine.

Now in R,  when I try the following:

>library(rJava)
>.jinit()
>.jaddClassPath("/home/Danish/java/rjbridge.jar")
> r<-.jnew("ObjectInfo")

I get,
Exception in thread "main" java.lang.ClassNotFoundException
        at RJavaClassLoader.findClass(RJavaClassLoader.java:195)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:242)
Error in .jnew("ObjectInfo") : Failed to create object of class
`ObjectInfo'
In addition: Warning message:
createObject.FindClass ObjectInfo failed in: .jnew("ObjectInfo")

Trying:
> r<-.jnew("rjbridge.ObjectInfo") 
Gives the following:

Exception in thread "main" java.lang.ClassNotFoundException
        at RJavaClassLoader.findClass(RJavaClassLoader.java:195)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:242)
Error in .jnew("rjbridge.ObjectInfo") : Failed to create object of class
`rjbridge/ObjectInfo'

I've spent a lot of time trying this in a number of different ways, but
to no avail. Will some kind soul help me out here?

Thanks
Danish
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This message is intended only for the personal and confidential use of the designated recipient(s) named above.  If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited.  This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such.  All information is subject to change without notice.

--------
IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within this communication (including any attachments) is not intended or written to be used and cannot be used for the purpose of (i) avoiding U.S. tax related penalties or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein.



More information about the R-help mailing list