2010-12-16 72 views

回答

55

有三種方法可以將jrxml編譯爲jasper。

  1. 您可以通過iReport設計器上的編譯按鈕(錘子標誌)直接編譯。

  2. 您可以使用ant進行編譯,如Ant Compile Sample所示。

    <target name="compile1"> 
        <mkdir dir="./build/reports"/> 
        <jrc 
        srcdir="./reports" 
        destdir="./build/reports" 
        tempdir="./build/reports" 
        keepjava="true" 
        xmlvalidation="true"> 
        <classpath refid="runClasspath"/> 
        <include name="**/*.jrxml"/> 
        </jrc> 
    </target> 
    

    下面是我當前項目的報告編譯任務。

    alt text

    除了從Daniel Rikowski

  3. 您還可以使用JasperCompileManager類從Java代碼進行編譯。

    JasperCompileManager.compileReportToFile(
           our_jasper_template.jrxml",//the path to the jrxml file to compile 
           our_compiled_template.jasper");//the path and name we want to save the compiled file to 
    
+0

您可以添加如何將數據源鏈接到示例#3嗎? – DanFromGermany 2013-07-03 12:28:54

+0

我建議你爲#1添加一個圖像 - 「錘子」標誌...圖片顯而易見。 – mmcrae 2016-04-21 14:54:04

8

我使用的iReport 2.0.2生成碧玉文件。

我沒有發現錘子標誌,但我有誰在iReport的程序文件文件夾中創建的文件碧玉菜單欄的菜單create > compile

iReport的日誌:「編譯VERS樂fichier .. 。\ SalesOrderItemsSubreportA4.jasper - > C:\ Program Files文件\的JasperSoft \的iReport-2.0.2 \ SalesOrderItemsSubreportA4.java」

+1

如果您有新問題,請點擊[問問題](http://stackoverflow.com/questions/ask)按鈕。如果有助於提供上下文,請包含此問題的鏈接。 – user35443 2015-01-07 08:55:25

+1

@ user35443,這不是一個新問題,實際上提供了對原始問題的答案。 – DB5 2015-01-07 09:12:08

9

與Maven是自動:

<plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>jasperreports-maven-plugin</artifactId> 
     <configuration> 
     <outputDirectory>target/${project.artifactId}/WEB-INF/reports</outputDirectory> 
    </configuration> 
     <executions> 
      <execution> 
       <phase>prepare-package</phase> 
       <inherited>false</inherited> 
       <goals> 
        <goal>compile-reports</goal> 
       </goals> 
      </execution> 
     </executions> 
     <dependencies> 
    <dependency> 
     <groupId>net.sf.jasperreports</groupId> 
     <artifactId>jasperreports</artifactId> 
     <version>3.7.6</version> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.16</version> 
     <type>jar</type> 
    </dependency> 
    </dependencies> 

2

使用版本5.1.0:

只需單擊預覽,它將爲您在同一個工作目錄中創建一個YourReportName.jasper。

3

如果您使用的是iReport,您可以輕鬆完成。

  1. 當您點擊預覽時,它會自動編譯。
  2. 有一個選項,使其complie。您可以通過選擇頁面進行編譯,然後右鍵單擊您將獲得編譯選項。
14

對於任何人碰到這個問題,誰使用Jaspersoft Studio到來(這,我想,是替代iReports,這是相當類似的,還是免費的,只是基於Eclipse),尋找「編譯報告」圖標上方您的.jrxml文件的編輯區域。它的圖標,首先在該圖標行中,是一個帶有二進制數字的文件(至少在版本5.6中)。2):

Jaspersoft Studio - compile report

單擊該圖標將產生在相同的目錄中的.jrxml文件.jasper文件,然後。

4

使用iReport designer 5.6.0,如果您希望在不預覽的情況下編譯多個jrxml文件 - 請轉到工具 - >大規模處理工具。選擇精化類型作爲「編譯文件」,選擇存儲所有jrxml報告的文件夾,並批量編譯它們。

4

在蝕,

  • 安裝Jaspersoft Studio爲蝕。
  • 右鍵單擊.jrxml文件,並選擇Open with JasperReports Book Editor
  • 打開Design標籤爲.jrxml文件。
  • 在窗口的頂部,您可以看到Compile Report圖標。