Compile JasperReports .jrxml to .jasper
With IDE (Integrated development environment)
In IDE Jaspersoft Studio (JSS) or the older version iReport Designer it is sufficient to press Preview.
The JasperReports design file .jrxml
will automatically be compiled to .jasper
in same folder as .jrxml
if no errors are present.
Another way is to press “Compile Report” button in JSS
or use the context menu “Compile Report” called from Report Inspector in iReport
With Apache Ant
<target name="compile" description="Compiles report designs specified using the 'srcdir' in the <jrc> tag." depends="prepare-compile-classpath">
<mkdir dir="./build/reports"/>
<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask">
<classpath refid="project-classpath"/>
</taskdef>
<jrc
srcdir="./reports"
destdir="./build/reports"
tempdir="./build/reports"
keepjava="true"
xmlvalidation="true">
<classpath refid="sample-classpath"/>
<include name="**/*.jrxml"/>
</jrc>
</target>
Apache Ant build tool needs to be correctly installed on your system
With Java
While it is possible to compile .jrxml
files into .jasper
files using Java code, this incurs a performance hit that is best avoided by pre-compiling .jrxml
files using the IDE. With that in mind, compiling .jrxml
files can be accomplished using the JasperCompileManager as follows:
JasperCompileManager.compileReportToFile(
"designFile.jrxml", //Relative or absoulte path to the .jrxml file to compile
"compiled.jasper"); //Relative or absolute path to the compiled file .jasper
With Apache Maven
The JasperReports-plugin by Alex Nederlof is a good alternative of abandoned org.codehaus.mojo:jasperreports-maven-plugin plugin.
The adding of plugin is a typical, simple procedure:
<build>
<plugins>
<plugin>
<groupId>com.alexnederlof</groupId>
<artifactId>jasperreports-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>jasper</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/main/resources/jrxml</sourceDirectory>
<outputDirectory>${project.build.directory}/jasper</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
The command for compilation with Maven:
mvn jasperreports:jasper
The jasper files will be created in ${project.build.directory}/jasper folder (for example, in /target/jasper)