I am trying to get rJava to load the htmlunit java package 
(http://htmlunit.sourceforge.net/).  rJava does not seem to be able to load and 
find the class in this package.  This issue is the same on Windows 7 and Fedora 
17 computers.

rJava will load and init because I can see java.util.* classes, java.net.* 
classes, java.io.IOException, and cssparser classes.  cssparser is required by 
htmlunit.

Thanks for you help.
Joe W. Byers

The following is a script the reproduces the issue an contains command with 
results as comments.
#rJava htmlunit problem on Windows and Linux (64 bit installs)
require(rJava)

# if using linux Fedora 17 or above, install htmlunit packages using yum or 
prefered 
#software updater.  If using 16 or below a manual install of htmlunit and 
cssparser 
#packages is required to /usr/share/java.  The following jar file names will 
need to 
# be modified for the system.

#Windows
#srchpath = 'C:\\path\\to\\jars';
#Linux
#srchpath = '/usr/share/java'; # or other location where jars are installed

#windows
jarfile  = c('cssparser-0.9.8.jar' ,'htmlunit-2.11.jar', 
'htmlunit-core-js-2.11.jar');
#linux Fedora 17 or above, otherwise modify with version
#jarfile  = c('cssparser.jar' ,'htmlunit.jar', 'htmlunit-core-js.jar');

.jinit();

.jclassPath();
#[1] "C:\\R\\library\\rJava\\java"

for (i in 1:length(jarfile)) {
 .jaddClassPath( file.path(srchpath, jarfile[i]));

}
.jclassPath();
#[1] "C:\\R\\library\\rJava\\java"                         
#[2] "C:\\libs\\external\\jar\\cssparser-0.9.8.jar"      
#[3] "C:\\libs\\external\\jar\\htmlunit-2.11.jar"        
#[4] "C:\\libs\\external\\jar\\htmlunit-core-js-2.11.jar"

attach( javaImport(packages = "com.steadystate.css.parser"), pos= 2, name = 
'com.steadystate.css.parser');
attach( javaImport(packages = "com.gargoylesoftware.htmlunit"), pos= 2, name = 
'htmlunit:com.gargoylesoftware.htmlunit');
attach( javaImport(packages = "java.io.IOException"), pos= 2, name = 
'java.io.IOException');
attach(javaImport(packages = "java.net"), pos=2, name= 'java.net');
attach(javaImport(packages = "java.util"), pos=2, name= 'java.util');
   
#attach( javaImport(packages = "com.gargoylesoftware.htmlunit.html"), pos= 2, 
name = 'com.gargoylesoftware.htmlunit.html');
search();
# [1] ".GlobalEnv"                            
# [2] "java.util"                             
# [3] "java.net"                              
# [4] "java.io.IOException"                   
# [5] "htmlunit:com.gargoylesoftware.htmlunit"
# [6] "com.steadystate.css.parser"            
# [7] "package:svSocket"                      
# [8] "package:TinnR"                         
# [9] "package:R2HTML"                        
#[10] "package:Hmisc"                         
#[11] "package:Formula"                       
#[12] "package:survival"                      
#[13] "package:splines"                       
#[14] "package:tcltk"                         
#[15] "package:rJava"                         
#[16] "package:stats"                         
#[17] "package:graphics"                      
#[18] "package:grDevices"                     
#[19] "package:utils"                         
#[20] "package:datasets"                      
#[21] "package:R.utils"                       
#[22] "package:R.oo"                          
#[23] "package:R.methodsS3"                   
#[24] "package:methods"                       
#[25] "SciViews:TempEnv"                      
#[26] "Autoloads"                             
#[27] "package:base"       


#test if java.net.URL methods seen URL
.jmethods(java.net.URL)  
# [1] "public boolean java.net.URL.equals(java.lang.Object)"                    
                            
# [2] "public java.lang.String java.net.URL.toString()"                         
                            
# [3] "public synchronized int java.net.URL.hashCode()"                         
                            
# [4] "public final java.io.InputStream java.net.URL.openStream() throws 
java.io.IOException"               
# [5] "public java.lang.String java.net.URL.getPath()"                          
                            
# [6] "public java.lang.String java.net.URL.getAuthority()"                     
                            
# [7] "public java.lang.String java.net.URL.getQuery()"                         
                            
# [8] "public java.net.URI java.net.URL.toURI() throws 
java.net.URISyntaxException"                         
# [9] "public java.lang.String java.net.URL.getFile()"                          
                            
#[10] "public java.lang.String java.net.URL.getHost()"                          
                            
#[11] "public java.lang.String java.net.URL.getProtocol()"                      
                            
#[12] "public java.net.URLConnection java.net.URL.openConnection() throws 
java.io.IOException"              
#[13] "public java.net.URLConnection 
java.net.URL.openConnection(java.net.Proxy) throws java.io.IOException"
#[14] "public java.lang.String java.net.URL.getRef()"                           
                            
#[15] "public final java.lang.Object java.net.URL.getContent() throws 
java.io.IOException"                  
#[16] "public final java.lang.Object java.net.URL.getContent(java.lang.Class[]) 
throws java.io.IOException" 
#[17] "public int java.net.URL.getPort()"                                       
                            
#[18] "public java.lang.String java.net.URL.getUserInfo()"                      
                            
#[19] "public boolean java.net.URL.sameFile(java.net.URL)"                      
                            
#[20] "public int java.net.URL.getDefaultPort()"                                
                            
#[21] "public static void 
java.net.URL.setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)"      
  
#[22] "public java.lang.String java.net.URL.toExternalForm()"                   
                            
#[23] "public final void java.lang.Object.wait() throws 
java.lang.InterruptedException"                     
#[24] "public final void java.lang.Object.wait(long,int) throws 
java.lang.InterruptedException"             
#[25] "public final native void java.lang.Object.wait(long) throws 
java.lang.InterruptedException"          
#[26] "public final native java.lang.Class java.lang.Object.getClass()"         
                            
#[27] "public final native void java.lang.Object.notify()"                      
                            
#[28] "public final native void java.lang.Object.notifyAll()"                   
 
#test if cssparser methods seen for Token
.jmethods(Token)
# [1] "public java.lang.String com.steadystate.css.parser.Token.toString()"     
                                      
# [2] "public java.lang.Object com.steadystate.css.parser.Token.getValue()"     
                                      
# [3] "public static com.steadystate.css.parser.Token 
com.steadystate.css.parser.Token.newToken(int,java.lang.String)"
# [4] "public static com.steadystate.css.parser.Token 
com.steadystate.css.parser.Token.newToken(int)"                 
# [5] "public final void java.lang.Object.wait() throws 
java.lang.InterruptedException"                               
# [6] "public final void java.lang.Object.wait(long,int) throws 
java.lang.InterruptedException"                       
# [7] "public final native void java.lang.Object.wait(long) throws 
java.lang.InterruptedException"                    
# [8] "public boolean java.lang.Object.equals(java.lang.Object)"                
                                      
# [9] "public native int java.lang.Object.hashCode()"                           
                                      
#[10] "public final native java.lang.Class java.lang.Object.getClass()"         
                                      
#[11] "public final native void java.lang.Object.notify()"                      
                                      
#[12] "public final native void java.lang.Object.notifyAll()"                   
       
#create a basic  java vector object
        v <- new( Vector )
        v
#[1] "Java-Object{[]}"
        
#create a basic  java IOEXCEPTION object
        v <- new( java.io.IOException )
  v
#[1] "Java-Object{java.io.IOException}"
  
#try find the basic vector class
.jfindClass(Vector);
#[1] "Java-Object{class java.util.Vector}"

#try find the cssparser Token class
.jfindClass(Token);
#[1] "Java-Object{class com.steadystate.css.parser.Token}"
    
#all of these worked try htmlunit
.jfindClass(WebClient);
#Error in inherits(cl, "jclassName") : object 'WebClient' not found
#---------fails with class not found error

.jmethods(WebClient);
#Error in is(o, "jobjRef") : object 'WebClient' not found
#
#---------fails with class not found error

#try full path    
.jmethods(com.gargoylesoftware.htmlunit.WebClient)
#Error in is(o, "jobjRef") : 
#  object 'com.gargoylesoftware.htmlunit.WebClient' not found
#
#same error                             
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to