0

我想为 JasperReport 运行示例演示,因此我下载了该文件,但是当我根据 Jasperreport 文档在 Windows 7 命令行中键入以下内容时:

C:\jasperreports-4.7.0\demo\samples\barbecue>ant run

我收到以下错误:

项目 "barbecue" 中不存在目标 "run" 。

那么可能是什么问题?

::更新:: 在我输入ant –pCMD 后,我得到以下信息:-

C:\jasperreports-4.7.0\demo\samples\barbecue>ant -p
Buildfile: C:\jasperreports-4.7.0\demo\samples\barbecue\build.xml
Shows how barcodes could be included in reports using the Barbecue component.
Main targets:

 clean          Deletes all the generated files.
 compile        Compiles the XML report design and produces the .jasper file.
 csv            Generates a CSV version of the report by converting the .jrprint
 file.
 decompile      Decompiles a .jasper file into a .jrxml file.
 docx           Generates a DOCX version of the report by converting the .jrprin
t file.
 fill           Fills the compiled report design with data and produces the .jrp
rint file.
 html           Generates an HTML version of the report by converting the .jrpri
nt file.
 javac          Compiles the java source files of the test application.
 jxl            Generates an XLS version of the report by converting the .jrprin
t file using the JExcelApi library.
 ods            Generates an ODS version of the report by converting the .jrprin
t file.
 odt            Generates an ODT version of the report by converting the .jrprin
t file.
 pdf            Generates a PDF version of the report by converting the .jrprint
 file.
 pptx           Generates a PPTX version of the report by converting the .jrprin
t file.
 print          Sends the report in the .jrprint file to the printer.
 rtf            Generates an RTF version of the report by converting the .jrprin
t file.
 test           Runs the sample.
 view           Launches the report viewer to preview the report stored in the .
jrprint file.
 viewDesign     Launches the design viewer to preview the compiled report design
.
 viewDesignXml  Launches the design viewer to preview the XML report design.
 viewXml        Launches the report viewer to preview the generated report store
d in an XML file.
 writeApi       Generates a .java version of the report by converting the .jrxml
 file.
 writeApiXml    Generates a .jrxml version of the report by executing the API ve
rsion of the report design.
 xhtml          Generates an XHTML version of the report by converting the .jrpr
int file.
 xls            Generates an XLS version of the report by converting the .jrprin
t file using the POI library.
 xlsx           Generates an XLSX version of the report by converting the .jrpri
nt file.
 xml            Generates an XML version of the report by converting the .jrprin
t file.
 xmlEmbed       Generates an XML version of the report by converting the .jrprin
t file.
Default target: test

:::::UPDATED2:::::ant test为图表演示键入但问题仍然存在:-

C:\jasperreports-4.7.0\demo\samples\charts>ant test
Buildfile: C:\jasperreports-4.7.0\demo\samples\charts\build.xml

test:
     [echo] ===================================
     [echo]  Charts Sample
     [echo] ===================================

clean:

clean-sample:

javac:

javac:
    [mkdir] Created dir: C:\jasperreports-4.7.0\demo\samples\charts\build\classe
s
    [javac] C:\jasperreports-4.7.0\demo\samples\build.xml:41: warning: 'includea
ntruntime' was not set, defaulting to build.sysclasspath=last; set to false for
repeatable builds
    [javac] Compiling 2 source files to C:\jasperreports-4.7.0\demo\samples\char
ts\build\classes
    [javac] warning: [options] bootstrap class path not set in conjunction with
-source 1.6
    [javac] Note: C:\jasperreports-4.7.0\demo\samples\charts\src\ChartsApp.java
uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 1 warning
     [copy] Copied 5 empty directories to 5 empty directories under C:\jasperrep
orts-4.7.0\demo\samples\charts\build\classes

compile:

compile:
    [mkdir] Created dir: C:\jasperreports-4.7.0\demo\samples\charts\build\report
s
      [jrc] Compiling 24 report design files.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\MultipleAx
isChartReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\XYBarChart
TimePeriodReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\XYAreaChar
tReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\Pie3DChart
Report.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\StackedBar
3DChartReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\MeterChart
Report.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\XYBarChart
Report.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\StackedAre
aChartReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\Candlestic
kChartReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\HighLowCha
rtReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\XYLineChar
tReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\BubbleChar
tReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\Thermomete
rChartReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\StackedBar
ChartReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\ScatterCha
rtReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\TimeSeries
ChartReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\SubDataset
ChartReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\AreaChartR
eport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\LineChartR
eport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\XYBarChart
TimeSeriesReport.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\GanttChart
Report.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\PieChartRe
port.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\Bar3DChart
Report.jrxml ... OK.
      [jrc] File : C:\jasperreports-4.7.0\demo\samples\charts\reports\BarChartRe
port.jrxml ... OK.

test:
     [java] net.sf.jasperreports.engine.JRException: java.sql.SQLException: sock
et creation error
     [java]     at net.sf.jasperreports.engine.util.AbstractSampleApp.getDemoHsq
ldbConnection(AbstractSampleApp.java:158)
     [java]     at ChartsApp.fill(ChartsApp.java:83)
     [java]     at ChartsApp.test(ChartsApp.java:63)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:57)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:43)
     [java]     at java.lang.reflect.Method.invoke(Method.java:601)
     [java]     at net.sf.jasperreports.engine.util.AbstractSampleApp.executeTas
k(AbstractSampleApp.java:94)
     [java]     at net.sf.jasperreports.engine.util.AbstractSampleApp.main(Abstr
actSampleApp.java:179)
     [java]     at ChartsApp.main(ChartsApp.java:54)
     [java] Caused by: java.sql.SQLException: socket creation error
     [java]     at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
     [java]     at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)
     [java]     at org.hsqldb.jdbcDriver.getConnection(Unknown Source)
     [java]     at org.hsqldb.jdbcDriver.connect(Unknown Source)
     [java]     at java.sql.DriverManager.getConnection(DriverManager.java:579)
     [java]     at java.sql.DriverManager.getConnection(DriverManager.java:221)
     [java]     at net.sf.jasperreports.engine.util.AbstractSampleApp.getDemoHsq
ldbConnection(AbstractSampleApp.java:150)
     [java]     ... 9 more

BUILD SUCCESSFUL
Total time: 8 seconds

C:\jasperreports-4.7.0\demo\samples\charts>ant run
Buildfile: C:\jasperreports-4.7.0\demo\samples\charts\build.xml

BUILD FAILED
Target "run" does not exist in the project "charts".

Total time: 0 seconds
4

2 回答 2

3

Java 错误就像一场车祸。一辆车会撞到另一辆车,导致第一辆车撞上路灯。路灯倾倒并撞到一辆爆炸的汽油卡车。

最后,你有毁灭、火灾和死亡。然而,整个事情的开始是因为司机忙着发短信,没有在停车标志前停下来。

您有一长串错误消息,但最重要的是最开始的错误消息:

net.sf.jasperreports.engine.JRException: java.sql.SQLException: socket creation error
     [java]     at net.sf.jasperreports.engine.util.AbstractSampleApp.getDemoHsqldbConnection(AbstractSampleApp.java:158)

这是一个套接字创建错误

此错误似乎指出您无法连接到服务器或数据库。

而且,这就是我能做到的。我真的不认识 Jasper,但我确实找到了这个。这对你有帮助吗?

是否有您应该运行的服务器,或者您需要连接的未创建的数据库?您是否有阻止连接到服务器/数据库的防火墙。(我倾向于数据库问题,因为我确实在您的错误消息中看到了有关hsqldbsql的内容。

我认为您不是 Java 开发人员,因为您似乎对 Ant 和它的build.xml文件感到困惑。有人可以帮助你吗?如果可以,请查看build.xml并查看目标测试在做什么。它正在运行一个 Java 命令,您可以尝试在 Ant 之外运行该命令。有时,这会给你更多的信息。

于 2012-08-30T14:04:12.643 回答
2

您应该运行ant test命令来运行示例(清理、编译和生成所有格式的报告:xls、pdf 等)。

要在JRViewer中查看报告,您应该运行ant view命令。

结果(输出)ant test将是:

d:\java\jasperreports-4.5.1\demo\samples\barbecue>ant test
Buildfile: d:\java\jasperreports-4.5.1\demo\samples\barbecue\build.xml

test:
     [echo] ===================================
     [echo]  Barbecue Sample
     [echo] ===================================

clean:

clean-sample:

javac:

javac:
    [mkdir] Created dir: d:\java\jasperreports-4.5.1\demo\samples\barbecue\build
\classes
    [javac] d:\java\jasperreports-4.5.1\demo\samples\build.xml:41: warning: 'inc
ludeantruntime' was not set, defaulting to build.sysclasspath=last; set to false
 for repeatable builds
    [javac] Compiling 1 source file to d:\java\jasperreports-4.5.1\demo\samples\
barbecue\build\classes

compile:

compile:
    [mkdir] Created dir: d:\java\jasperreports-4.5.1\demo\samples\barbecue\build
\reports
      [jrc] Compiling 1 report design files.
      [jrc] File : d:\java\jasperreports-4.5.1\demo\samples\barbecue\reports\Bar
becueReport.jrxml ... OK.

test:
     [java] Filling time : 3198
     [java] PDF creation time : 993
     [java] XML creation time : 224
     [java] XML creation time : 44
     [java] HTML creation time : 109
     [java] RTF creation time : 98
     [java] XLS creation time : 364
     [java] XLS creation time : 248
     [java] CSV creation time : 6
     [java] ODT creation time : 95
     [java] ODS creation time : 12
     [java] DOCX creation time : 183
     [java] XLSX creation time : 103
     [java] PPTX creation time : 74
     [java] XHTML creation time : 56

BUILD SUCCESSFUL
Total time: 13 seconds

net.sf.jasperreports.engine.JRException: java.sql.SQLException: sock et creation error异常的反应:

您尝试启动的示例正在使用与HSQLDB服务器的连接。要启动 DB,您应该从该文件夹运行ant runServer命令。demo/hsqldb

有关如何运行示例的更多详细信息,您可以阅读这篇文章

于 2012-08-30T13:29:48.500 回答