我正在尝试将Jaspersoft Studio与DeployR脚本相结合。我正在使用微软here的这篇教程,它实际上是针对iReport ( Jaspersoft Studio的前一个解决方案)的。我已经像教程中那样将必要的jar文件添加到类路径,并在DeployR中部署了R脚本。
在Jasper中运行报告后,报告上没有任何内容,也没有给出错误。但是我有一个警告:No query executer factory class registered for deployrScript queries.
所以我猜问题是Jaspersoft Studio找不到deployrScript的类,尽管这个类jRQueryExecuter2
在类路径中!
在jrxml中,您可以看到以下声明:
<queryString language="deployrScript">
<![CDATA[<deployr url="http://127.0.0.1:8000/deployr">
<script filename="Cluster_Demo_Jasperserver.R" directory="root" author="testuser"/>
</deployr>]]>
</queryString>
整个jrxml是:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="deployrSample" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5a314889-9cd2-4943-ad5f-13ef1bd6ca74">
<parameter name="RRP_plotwidth" class="java.lang.Double" isForPrompting="false">
<defaultValueExpression><![CDATA[555]]></defaultValueExpression>
</parameter>
<parameter name="RRP_plotheight" class="java.lang.Double" isForPrompting="false">
<defaultValueExpression><![CDATA[555]]></defaultValueExpression>
</parameter>
<parameter name="RRP_dataset" class="java.lang.String">
<defaultValueExpression><![CDATA["iris"]]></defaultValueExpression>
</parameter>
<parameter name="RRP_clusters" class="java.lang.Integer">
<defaultValueExpression><![CDATA[3]]></defaultValueExpression>
</parameter>
<parameter name="RRP_clustering_type" class="java.lang.String">
<defaultValueExpression><![CDATA["hclust"]]></defaultValueExpression>
</parameter>
<queryString language="deployrScript">
<![CDATA[<deployr url="http://127.0.0.1:8000/deployr">
<script filename="Cluster_Demo_Jasperserver.R" directory="root" author="testuser"/>
</deployr>]]>
</queryString>
<field name="REPORT1" class="java.lang.String">
<fieldDescription><![CDATA[file:cluster_output.png]]></fieldDescription>
</field>
<pageHeader>
<band height="63" splitType="Stretch">
<image>
<reportElement x="30" y="10" width="50" height="37" uuid="4ce16c2b-5680-48b6-86e8-ce992c543a40"/>
<imageExpression><![CDATA["C:/Users/aort.png"]]></imageExpression>
</image>
</band>
</pageHeader>
<detail>
<band height="600" splitType="Stretch">
<image scaleImage="RetainShape" hAlign="Center">
<reportElement positionType="Float" x="100" y="40" width="353" height="218" uuid="f2294c37-5751-41f9-a3b4-fcfe80b69fec"/>
<imageExpression><![CDATA[$F{REPORT1}]]></imageExpression>
</image>
</band>
</detail>
</jasperReport>
和R脚本:
library(cluster)
#uncomment these lines to test in standalone mode
dataset <- "mtcars"
clusters <- 4
clustering_type <- 'hclust'
plotwidth<-555
plotheight<-555
if (dataset == 'iris') {
data <- iris[,1:4]
df <-data.frame(data$Sepal.Length, data$Sepal.Width)
} else if (dataset == 'mtcars') {
data <- mtcars
df <-data.frame(data$drat, data$disp)
} else {
stop("Enter a valid dataset")
}
if (clustering_type == 'kmeans') {
fit <- kmeans(df, clusters)
png("cluster_output.png", width=plotwidth, height=plotheight);
clusplot(df, fit$cluster, color=TRUE, shade=TRUE, labels=0, lines=0, main = dataset)
dev.off()
} else if (clustering_type == "hclust") {
d <- dist(as.matrix(df))
fit <-hclust(d)
png("cluster_output.png", width=plotwidth, height=plotheight);
plot(fit, main = dataset)
dev.off()
} else {
stop ("enter a valid clustering type")
}
DeployR代码:
library(cluster)
#uncomment these lines to test in standalone mode
#dataset <- "iris"
#clusters <- 4
#clustering_type <- 'hclust'
#plotwidth<-555
#plotheight<-555
if (dataset == 'iris') {
data <- iris[,1:4]
df <-data.frame(data$Sepal.Length, data$Sepal.Width)
} else if (dataset == 'mtcars') {
data <- mtcars
df <-data.frame(data$drat, data$disp)
} else {
stop("Enter a valid dataset")
}
if (clustering_type == 'kmeans') {
fit <- kmeans(df, clusters)
png("cluster_output.png", width=plotwidth, height=plotheight);
clusplot(df, fit$cluster, color=TRUE, shade=TRUE, labels=0, lines=0, main = dataset)
dev.off()
} else if (clustering_type == "hclust") {
d <- dist(as.matrix(df))
fit <-hclust(d)
png("cluster_output.png", width=plotwidth, height=plotheight);
plot(fit, main = dataset)
dev.off()
} else {
stop ("enter a valid clustering type")
}
我已经按照Narcis的建议向属性中添加了net.sf.jasperreports.query.executer.factory.deployrScript=com.revo.deployr.client.jasper.factory.RQueryExecuterFactory
,但是REPORT1字段仍然是空的,并且我在报告中什么也得不到。
我的问题是如何将DeployR添加到Jaspersoft Studio?
发布于 2016-07-18 16:35:12
您遵循的教程似乎没有详细介绍如何注册查询执行器(在DeployR自定义客户端库部分中的第9点)。
除了将jar文件添加到类路径之外,您还需要在Jaspersoft Studio中设置如下属性:
net.sf.jasperreports.query.executer.factory.[your_query_language_name]=[the_canonical_name_of_your_query_executer_factory_class]
在您的情况下,您应该具备:
net.sf.jasperreports.query.executer.factory.deployrScript=com.revo.deployr.client.jasper.factory.RQueryExecuterFactory
如果您计划在webapp服务器实例上使用此属性,则需要在<webapp-path>/WEB-INF/classes/jasperreports.properties
文件中为JasperReports设置相同的属性。在这种情况下,需要重新启动应用程序。
https://stackoverflow.com/questions/38398102
复制相似问题