【问题标题】:How do I compile jrxml to get jasper?如何编译 jrxml 以获取 jasper?
【发布时间】:2011-05-26 07:13:01
【问题描述】:

我有 jrxml 文件,我想编译它以获得 .jasper。如何编译并获取该 jasper 文件?

【问题讨论】:

    标签: java jasper-reports ireport jaspersoft-studio


    【解决方案1】:

    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>
      

      下面是我当前项目的报告编译任务。

      来自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
      

    【讨论】:

    • 你能添加如何将数据源链接到示例 #3 吗?
    • 我建议你为#1 添加一张图片——“锤子”标志...图片很明显。
    • iReport 设计器不再受支持。现在最好使用 Jaspersoft Studio。
    • 请将您的 ant build.xml 发布为文本,而不是图像。它被截断了,人们无法复制和粘贴它。
    【解决方案2】:

    对于遇到此问题并使用Jaspersoft Studio(我认为它正在取代 iReports;它非常相似,仍然是免费软件,只是基于 eclipse)的任何人,请在编辑器顶部查找“编译报告”图标.jrxml 文件的区域。它的图标,在该图标行的第一个,是一个带有二进制数字的文件(至少在 5.6.2 版本中):

    单击此图标将在与 .jrxml 文件相同的目录中生成 .jasper 文件。

    【讨论】:

      【解决方案3】:

      使用 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>
      </plugin>
      

      【讨论】:

      • prepare-package 如果您使用的是 sping 启动 jar,这非常重要。
      【解决方案4】:

      我正在使用 iReport 2.0.2 生成 jasper 文件。

      我没有找到锤子标志,但我在菜单栏中有一个菜单create &gt; compile,它在 iReport 程序文件文件夹中创建了 jasper 文件:

      IReport 日志:"Compilation vers le fichier... .\SalesOrderItemsSubreportA4.jasper -> C:\Program Files\JasperSoft\iReport-2.0.2\SalesOrderItemsSubreportA4.java"

      【讨论】:

      • 如果您有新问题,请点击 按钮提出问题。如果有助于提供上下文,请包含指向此问题的链接。
      • @user35443,这不是一个新问题,实际上提供了原始问题的答案。
      【解决方案5】:

      使用 iReport 设计器 5.6.0,如果您希望编译多个 jrxml 文件而不预览 - 转到工具 -> 大规模处理工具。选择Elaboration Type为“Compile Files”,选择所有jrxml报告存放的文件夹,批量编译。

      【讨论】:

        【解决方案6】:

        如果您使用 iReport,您可以轻松做到。

        1. 点击预览时会自动编译。
        2. 有一个选项可以使其符合要求。您可以通过选择页面进行编译,然后右键单击您将获得编译选项。

        【讨论】:

          【解决方案7】:

          在日食中,

          • 为 Eclipse 安装 Jaspersoft Studio
          • 右击.jrxml文件并选择Open with JasperReports Book Editor
          • .jrxml 文件打开Design 选项卡。
          • 您可以在窗口顶部看到Compile Report 图标。

          【讨论】:

            【解决方案8】:

            使用版本 5.1.0:

            只需单击预览,它将在同一工作目录中为您创建一个 YourReportName.jasper。

            【讨论】:

              【解决方案9】:
              1. 在 iReport Designer 中打开您的 .jrxml 文件。
              2. 打开报告检查器(窗口 -> 报告检查器)。
              3. 右键单击检查器顶部的报告名称,然后单击“编译报告”。

              您还可以预览您的报告,以便自动编译。

              【讨论】:

                【解决方案10】:

                如果您使用的是 Eclipse IDE,您只需在 .jrxml 文件中单击鼠标右键,然后单击编译选项

                【讨论】:

                  【解决方案11】:
                   **A full example of POM file**.
                  
                  Command to Build All **Jrxml** to **Jasper File** in maven
                  If you used eclipse then right click on the project and Run as maven Build and add goals antrun:run@compile-jasper-reports 
                  
                  
                  compile-jasper-reports is the id you gave in the pom file.
                  **<id>compile-jasper-reports</id>**
                  
                  
                  
                  
                  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
                    <modelVersion>4.0.0</modelVersion>
                  
                    <groupId>com.test.jasper</groupId>
                    <artifactId>testJasper</artifactId>
                    <version>0.0.1-SNAPSHOT</version>
                    <packaging>jar</packaging>
                  
                    <name>TestJasper</name>
                    <url>http://maven.apache.org</url>
                  
                    <properties>
                      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                    </properties>
                  
                    <dependencies>
                      <dependency>
                          <groupId>log4j</groupId>
                          <artifactId>log4j</artifactId>
                          <version>1.2.17</version>
                      </dependency>
                      <dependency>
                          <groupId>net.sf.jasperreports</groupId>
                          <artifactId>jasperreports</artifactId>
                          <version>6.3.0</version>
                      </dependency>
                      <dependency>
                          <groupId>net.sf.jasperreports</groupId>
                          <artifactId>jasperreports-fonts</artifactId>
                          <version>6.0.0</version>
                      </dependency>
                      <dependency>
                          <groupId>org.codehaus.groovy</groupId>
                          <artifactId>groovy-all</artifactId>
                          <version>2.4.6</version>
                      </dependency>
                      <dependency>
                          <groupId>com.itextpdf</groupId>
                          <artifactId>itextpdf</artifactId>
                          <version>5.5.6</version>
                      </dependency>
                      <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>3.8.1</version>
                        <scope>test</scope>
                      </dependency>
                  
                  
                    </dependencies>
                      <build>
                      <pluginManagement>
                      <plugins>
                           <plugin>
                              <groupId>org.apache.maven.plugins</groupId>
                              <artifactId>maven-compiler-plugin</artifactId>
                              <version>3.5</version>
                              <configuration>
                                  <source>1.8</source>
                                  <target>1.8</target>
                              </configuration>
                          </plugin>       
                          <plugin>
                              <groupId>org.apache.maven.plugins</groupId>
                              <artifactId>maven-antrun-plugin</artifactId>
                              <version>1.8</version>
                              <executions>
                                  <execution>
                                      <id>compile-jasper-reports</id>
                                      <goals>
                                          <goal>run</goal>
                                      </goals>
                                      <phase>generate-sources</phase>
                                      <configuration>
                                          <target>
                                              <echo message="Start compile of jasper reports" />
                                              <mkdir dir="${project.build.directory}/classes/reports"/>
                                              <echo message="${basedir}/src/main/resources/jasper/jasperreports" />
                                              <taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask"
                                                  classpathref="maven.compile.classpath" />
                                                  <jrc srcdir="${basedir}/src/main/resources/jasper/jasperreports" destdir="${basedir}/src/main/resources/jasper/jasperclassfile"
                                                    xmlvalidation="true">
                                                  <classpath refid="maven.compile.classpath"/>
                                                  <include name="**/*.jrxml" />
                                              </jrc>
                                          </target>
                                      </configuration>
                                  </execution>
                              </executions>
                          </plugin>
                      </plugins>
                      </pluginManagement>
                  </build>
                  </project>
                  

                  【讨论】:

                    【解决方案12】:

                    iReport 5.5.0 中,只需 右键单击 Report Inspector Bloc Window viewer 中的报告基础层次结构,然后点击编译报告

                    您现在可以在控制台中看到结果。如果没有错误,您可能会看到类似这样的内容。

                    【讨论】:

                      猜你喜欢
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      相关资源
                      最近更新 更多