Java 如何编译 jrxml 以获得 jasper?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4456779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 17:47:29  来源:igfitidea点击:

How do I compile jrxml to get jasper?

javaantjasper-reportsireportjaspersoft-studio

提问by Mohamed Saligh

In ant, how do I compile a .jrxmlfile to get a .jasper?

在 ant 中,如何编译.jrxml文件以获取.jasper

采纳答案by Sal Prima

There are three ways to compile jrxml to jasper.

将 jrxml 编译为 jasper 有三种方式。

  1. You can do direct compile via compile button (hammer logo) on iReport designer.

  2. You can use ant to compile as shown in the 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>
    

    Below is the report compile task on my current project.

    alt text

    addition from Daniel Rikowski:

  3. You can also use the JasperCompileManagerclass to compile from your java code.

    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
    
  1. 您可以通过 iReport 设计器上的编译按钮(锤子标志)直接编译。

  2. 您可以使用 ant 进行编译,如Ant 编译示例 中所示

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

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

    替代文字

    此外,从丹尼尔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
    

回答by Grégory

I'm using iReport 2.0.2 to generate the jasper file.

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

I didn't found the hammer logo, but I have a menu create > compilein the menu bar who create the the jasper file in the iReport program files folder :

我没有找到锤子徽标,但是我create > compile在菜单栏中有一个菜单,可以在 iReport 程序文件文件夹中创建 jasper 文件:

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

IReport 日志:“编译版本 le fichier....\SalesOrderItemsSubreportA4.jasper -> C:\Program Files\JasperSoft\iReport-2.0.2\SalesOrderItemsSubreportA4.java”

回答by leccionesonline

with maven it is automatic:

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

回答by Ali

Using Version 5.1.0:

使用 5.1.0 版:

Just click preview and it will create a YourReportName.jasper for you in the same working directory.

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

回答by Praveen P Moolekandathil

If you are using iReport you can easily do it.

如果您使用 iReport,您可以轻松完成。

  1. When you click preview it will automatically compile.
  2. There is an option to make it complie. You can compile by selecting the page then right click you will get the compile option.
  1. 当您单击预览时,它将自动编译。
  2. 有一个选项可以让它合规。您可以通过选择页面进行编译,然后右键单击您将获得编译选项。

回答by Amos M. Carpenter

For anyone coming across this question who uses Jaspersoft Studio(which, I think, is replacing iReports; it's quite similar, still freeware, just based on eclipse), look for the "Compile Report" icon on top of the editor area of your .jrxml file. Its icon, first in that line of icons, is a file with binary numbers on it (at least in version 5.6.2):

对于使用Jaspersoft Studio(我认为它正在取代 iReports;它非常相似,仍然是免费软件,仅基于 eclipse)遇到此问题的任何人,请在 . jrxml 文件。它的图标,在该行图标中的第一个,是一个带有二进制数字的文件(至少在 5.6.2 版本中):

Jaspersoft Studio - compile report

Jaspersoft Studio - 编译报告

Clicking this icon will generate the .jasper file in the same directory as the .jrxml file.

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

回答by Vivek

Using iReport designer 5.6.0, if you wish to compile multiple jrxml files without previewing - go to Tools -> Massive Processing Tool. Select Elaboration Type as "Compile Files", select the folder where all your jrxml reports are stored, and compile them in a batch.

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

回答by Lucky

In eclipse,

在日食中,

  • Install Jaspersoft Studiofor eclipse.
  • Right click the .jrxmlfile and select Open with JasperReports Book Editor
  • Open the Designtab for the .jrxmlfile.
  • On top of the window you can see the Compile Reporticon.
  • 为 Eclipse安装Jaspersoft Studio
  • 右键单击.jrxml文件并选择Open with JasperReports Book Editor
  • 打开文件的Design选项卡.jrxml
  • 在窗口顶部,您可以看到Compile Report图标。

回答by Hardik Dobariya

 **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>

回答by rickbala_

  1. Open your .jrxml file in iReport Designer.
  2. Open the Report Inspector (Window -> Report Inspector).
  3. Right-click your report name on the top of the inspector and then click "Compile Report".
  1. 在 iReport 设计器中打开您的 .jrxml 文件。
  2. 打开报告检查器(窗口 -> 报告检查器)。
  3. 右键单击检查器顶部的报告名称,然后单击“编译报告”。

You can also Preview your report so it's automatically compiled.

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