我正在嘗試使用R調用方將回歸R代碼集成到我的j2ee項目中。 我的數據源來自mysql數據庫。所以我使用RMYSQL作爲包。 下的Java項目我的代碼工作正常,但當我把它變成支撐類,它拋出一個異常:java.lang.NoClassDefFoundError: rcaller/RCaller
java.lang.NoClassDefFoundError:java -ee中的rcaller/RCaller
在行家依賴它存在Rcaller的唯一版本2.8。我需要2.5版本,所以我添加了它來手動構建路徑。
的支持bean的方法是:
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());
}
而且爲了顯示JSF頁面的圖形,我已要求該函數如下:
#{video_R_IntegrationBean.Test3()}
檢查它:http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java –