gpt4 book ai didi

java.lang.NoClassDefFoundError : rcaller/RCaller in java-ee

转载 作者:行者123 更新时间:2023-12-01 09:41:49 27 4
gpt4 key购买 nike

我正在尝试使用 R 调用程序将回归 R 代码集成到我的 j2ee 项目中。我的数据源来自mysql数据库。所以我使用 RMYSQL 作为包。我的代码在 java 项目下工作正常,但是当我将其移动到支持 bean 类时,它会抛出异常: java.lang.NoClassDefFoundError: rcaller/RCaller

在maven依赖中,仅存在2.8版本的Rcaller。我需要 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()} 

最佳答案

既然使用了maven,就必须遵循maven的方式。

如果您有这个 2.5 版本的 jar,请将其安装在本地存储库或自定义存储库中。请参阅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

一旦将其安装到存储库中,您必须在 pom.xml 中将其声明为依赖项,当然不要忘记在 repositories 部分引用您的本地存储库.

关于java.lang.NoClassDefFoundError : rcaller/RCaller in java-ee,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38392311/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com