0

I am trying to integrate regression R code into my j2ee project using R caller. My datasource is from mysql database. So I used RMYSQL as package. My code work fine under java project but when I moved it into backing bean class it throws an exception: java.lang.NoClassDefFoundError: rcaller/RCaller

In maven dependency it exist only version 2.8 of Rcaller. And I'm in need to 2.5 version so I haved added it to build path manually.

The backing bean method is:

try {

       RCaller caller = new RCaller();
       RCode code = new RCode();  

       caller.setRscriptExecutable("Rscript.exe");
       code.clear();
       caller.setRCode(code);

       code.R_require("RMySQL");
       code.R_require("rpart");


       code.addRCode("mydb= dbConnect(MySQL(),user='root',password='root',dbname='db',host='localhost')"); 
       code.addRCode("rs= dbSendQuery(mydb,'select * from table')"); 
       code.addRCode("data = fetch(rs,n=-1)");  
       code.addRCode("data= data[data[['cred']]>0,]");  
       code.addRCode("data$navig <- ifelse(data$navig == 'Chrome',1,ifelse(data$navig == 'Firefox',2,ifelse(data$navig == 'Android',3,ifelse(data$navig == 'iPhone',4,9))))");  
       code.addRCode("data$rate =as.factor(data$rate)");  
       code.addRCode("ad.apprentissage= rpart(rate~vqs+ibt+tbt+bf+n+down+ping, data=data,minsplit = 7)");  
       code.addRCode("predArbreDecision=predict(ad.apprentissage,newdata=data,type='class') ");  
       code.addRCode("table(data$rate, predArbreDecision)");  


       File file = code.startPlot();
      // code.addRCode("ggplot(df, aes(x, y)) + geom_point() + geom_smooth(method='lm') + ggtitle('y = f(x)')");
code.addRCode("plot(ad.apprentissage,main='Arbre de décision de la vidéo Streaming')");
code.addRCode("text(ad.apprentissage)");
       caller.runOnly();
       ImageIcon ii = code.getPlot(file);
       code.showPlot(file);

   } catch (Exception e) {
       System.out.println(e.toString());
   } 

And in order to display the graph in jsf page, I have called that function as following:

 #{video_R_IntegrationBean.Test3()} 
Manel Chaabene
  • 187
  • 1
  • 3
  • 14

1 Answers1

1

Since you are using maven, you have to follow the maven way.

If you have this jar of 2.5 version, please install it either in your local repository, or in a custom repository. Please see here

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file  -Dfile=path-to-your-artifact-jar \
                                                                              -DgroupId=your.groupId \
                                                                              -DartifactId=your-artifactId \
                                                                              -Dversion=version \
                                                                              -Dpackaging=jar \
                                                                              -DlocalRepositoryPath=path-to-specific-local-repo

Once it is installed in your repository, you have to declare it in your pom.xml as dependency and of course dont forget to reference your local repository in repositories section.

Apostolos
  • 10,033
  • 5
  • 24
  • 39
  • I followed what you said, now the jar fil is successfully present in maven dependencies but same error occured :java.lang.NoClassDefFoundError: rcaller/RCaller – Manel Chaabene Jul 15 '16 at 10:39
  • i guess this is the correct version, right? i mean, if it wanst it wouldnt compile. does `mvn clean package` add this 2.5 jar inside the `WEB-INF\lib` folder of your generated war file? – Apostolos Jul 15 '16 at 11:29
  • No it's not present under WEB-INF\lib. But it is present in maven dependency. I have added it as following: RCaller-2.5 RCaller-2.5 2.5 system ${basedir}/lib/RCaller-2.5.jar – Manel Chaabene Jul 15 '16 at 11:37
  • no please dont use system scope. you shouldnt add it as system scope. if you must use it that way, the point it to be inside the `src/main/webapp/WEB-INF/lib` folder of your maven project and copy it there. – Apostolos Jul 15 '16 at 11:38