I have jrxml file, I want to compile this to get .jasper. How do I compile and get that jasper file?
12 Answers
There are three ways to compile jrxml to jasper.
You can do direct compile via compile button (hammer logo) on iReport designer.
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.
addition from Daniel Rikowski :
You can also use the JasperCompileManager class 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
-
Can you add how to link a datasource to example #3 ? – Daniel W. Jul 03 '13 at 12:28
-
I suggest you add an image for #1 - the "hammer" logog... Picture makes it obvious. – Don Cheadle Apr 21 '16 at 14:54
-
iReport Designer is no longer supported. It is better to use Jaspersoft Studio now. – Pierre Sep 03 '18 at 08:46
-
Please post your ant build.xml as text, not as image. It's truncated, and people cannot copy & paste it. – Robert Dec 20 '19 at 17:49
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):
Clicking this icon will generate the .jasper file in the same directory as the .jrxml file.

- 4,848
- 4
- 42
- 72
with maven it is automatic:
<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>

- 9,683
- 9
- 53
- 71

- 618
- 1
- 8
- 23
-
prepare-package is realy important if you are working with sping boot jar. – Arundev Jun 11 '18 at 14:43
I'm using iReport 2.0.2 to generate the jasper file.
I didn't found the hammer logo, but I have a menu create > compile
in the menu bar who create the the jasper file in the iReport program files folder :
IReport Logs :"Compilation vers le fichier... .\SalesOrderItemsSubreportA4.jasper -> C:\Program Files\JasperSoft\iReport-2.0.2\SalesOrderItemsSubreportA4.java"

- 1,473
- 1
- 17
- 28
-
1If you have a new question, please ask it by clicking the [Ask Question](http://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. – user35443 Jan 07 '15 at 08:55
-
1@user35443, this is not a new question and actually provides an answer to the original question. – DB5 Jan 07 '15 at 09:12
In eclipse,
- Install Jaspersoft Studio for eclipse.
- Right click the
.jrxml
file and selectOpen with JasperReports Book Editor
- Open the
Design
tab for the.jrxml
file. - On top of the window you can see the
Compile Report
icon.

- 16,787
- 19
- 117
- 151
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.

- 51
- 1
- 1
If you are using iReport you can easily do it.
- When you click preview it will automatically compile.
- There is an option to make it complie. You can compile by selecting the page then right click you will get the compile option.

- 568
- 1
- 6
- 16
- Open your .jrxml file in iReport Designer.
- Open the Report Inspector (Window -> Report Inspector).
- Right-click your report name on the top of the inspector and then click "Compile Report".
You can also Preview your report so it's automatically compiled.

- 31
- 4
if you are using the eclipse IDE you just do a right click in the .jrxml file and then click the compile option

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

- 21
- 3
In iReport 5.5.0, just right click the report base hierarchy in Report Inspector Bloc Window viewer, then click Compile Report
You can now see the result in the console down. If no Errors, you may see something like this.

- 424
- 1
- 6
- 16