Generate .jasper with maven plugin - java

I´m looking to improve the performance of my application, which has two types of reports, and compile then at execution time like this :
final JasperDesign design = JRXmlLoader.load(input);
final JasperReport compiledReport = JasperCompileManager.compileReport(design);
This code executes every time when the user wants to see the report on the app.
To avoid this, I´m trying to execute the compilation of the .jrxml through maven jasperreports plugin, but it doesn't work, and there isn't an error on console.
The .jasper files don't appear in my directory "outputDirectory".
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<inherited>false</inherited>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/main/resources/reports</sourceDirectory>
<outputDirectory>src/main/resources/reports/jasper</outputDirectory>
<compiler>net.sf.jasperreports.engine.design.JRJdtCompiler</compiler>
</configuration>
</plugin>

I know this is old, but this happened to me when I defined the plugin in the <pluginManagement> section of the POM instead of in <plugins>.

This was the pom config I used
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
<configuration>
<!-- jrxml file directory-->
<sourceDirectory>src\\main\\resources\\reports\\template</sourceDirectory>
<sourceFileExt>.jrxml</sourceFileExt>
<compiler>net.sf.jasperreports.engine.design.JRJavacCompiler</compiler>
<!-- Destination for jasper file -->
<outputDirectory>src\\main\\resources\\reports\\jasper</outputDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<!-- These plugins are used to specify correct version for jrxml xml validation -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

Related

JAI I/O Tools missing when launched with java whereas present when run with Maven

My java program involves PDFs. Some of them have JPEG2000 images embedded. So I added the following lines to my pom.xml :
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.26</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.26</version>
</dependency>
<!--Please note the absence of jai imageio core
to make the program work. It will be provided by tika parser -->
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-jpeg2000</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
<version>3.0.2</version>
</dependency>
...
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
<type>jar</type>
</dependency>
...
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>${mainClass}</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.3.9</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<mainClass>${mainClass}</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.0</version>
<configuration>
<release>11</release>
<source>${javaVersion}</source>
<target>${javaVersion}</target>
</configuration>
</plugin>
</plugins>
</build>
Now if I run the program (from the project directory) with Maven : /pathTo/netbeans/java/maven/bin/mvn "-Dexec.args=-classpath %classpath" -DOMP_THREAD_LIMIT=1 -DskipTests=true exec:java the JPEG2000 dependency is loaded and the program works as expected.
However if I run the program (from the project directory) with Java : java -Dprism.order=sw --module-path /home/user/pathTo/lib/javafx-sdk-11.0.2/lib --add-modules ALL-MODULE-PATH -verbose:class -jar target/myBig-jar-with-dependencies.jar I get "org.apache.pdfbox.filter.MissingImageReaderException: Cannot read JPEG2000 image: Java Advanced Imaging (JAI) Image I/O Tools are not installed" although JAI and JPEG2000 do appear in loaded classes (see -verbose:class) :
[7,434s][info][class,load] com.github.jaiimageio.jpeg2000.impl.J2KImageReader source: file://path/to/project/target/myJar_with_dependencies.jar [7,434s][info][class,load] javax.imageio.ImageReadParam source: jrt:/java.desktop [7,435s][info][class,load] com.github.jaiimageio.jpeg2000.J2KImageReadParam source: file://path/to/project/target/myJar_with_dependencies.jar [7,435s][info][class,load] com.github.jaiimageio.jpeg2000.impl.J2KImageReadParamJava source: file://path/to/project/target/myJar_with_dependencies.jar [7,435s][info][class,load] com.github.jaiimageio.jpeg2000.impl.J2KMetadata source: file://path/to/project/target/myJar_with_dependencies.jar
To make the program work as expected with java I have to put the JPEG2000 jar in the lib path provided to the --module-path argument. But I'd rather only have clear dependencies in pom.xml to ease maintain the code in the future, instead of having also dependencies in the JavaFX lib folder in user directory.
So my question is what is the equivalent java command to the maven command shown above ?
Any help appreciated
Not sure this could help since it sounds more like wizardry! I updated to Tika 2.3 (moved tika-parser dependency to tika-parsers-standard-package) and as I got "package org.apache.tika.config does not exist" (although it does), I finally restarted Netbeans, built the jar, launched it via javacommand and it is now working as expected.

Get JRE from maven

Is it still possible to download JRE from maven as a zip file, so that one can include it in the packaged product? I found this code, which doesn't work anymore:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.oracle</groupId>
<artifactId>jre</artifactId>
<version>1.8.141</version>
<type>zip</type>
<classifier>windows-i586</classifier>
<outputDirectory>${basedir}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
UPDATE: Looks like such thing could only work after uploading the zip file to the own maven repo...
Change the version 1.8.141 to 1.8.0_131. The latest maven has this one only:
<!-- https://mvnrepository.com/artifact/com.oracle.java/jre -->
<dependency>
<groupId>com.oracle.java</groupId>
<artifactId>jre</artifactId>
<version>1.8.0_131</version>
</dependency>
EDIT :As per the comments from OP
This example here is for a dependency. What I need is a maven goal to
copy unzipped JRE to a folder. And actually I do need a specific JRE
version. So currently, the solution is to install the JRE zip file in
my maven repo and unpack it with maven goal.
Copying and unzipping the jre artifact to another location may be achieved by Maven Dependency Plugin
<project>
[...]
<dependencies>
<dependency>
<groupId>com.oracle.java</groupId>
<artifactId>jre</artifactId>
<version>1.8.0_131</version>
</dependency>
</dependencies>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>unpack</id>
<phase>validate</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.oracle.java</groupId>
<artifactId>jre</artifactId>
<type>zip</type>
<outputDirectory>/path/to/alternateLocation</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>

Multiple maven plugins to run a phase

I am doing a maven smartbear soapui project. I have dependency for two plugins. `
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-pro-maven-plugin</artifactId>
<version>5.1.2</version>
<executions>
<execution>
<id>pro</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<projectFile>${projectFile}</projectFile>
<outputFolder>${basedir}/target/surefire-reports</outputFolder>
<junitReport>true</junitReport>
<exportAll>true</exportAll>
<printReport>true</printReport>
<testFailIgnore>true</testFailIgnore>
</configuration>
</execution>
</executions>
<configuration>
<soapuiProperties>
<property>
<name>soapui.logroot</name>
<value>${project.build.directory}/surefire-reports/</value>
</property>
<property>
<name>soapui.https.protocols</name>
<value>TLSv1.2,SSLv3</value>
</property>
</soapuiProperties>
</configuration>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.19.1</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.github.redfish4ktc.soapui</groupId>
<artifactId>maven-soapui-extension-plugin</artifactId>
<version>4.6.4.2</version>
<executions>
<execution>
<id>redfish</id>
<phase>test</phase>
<configuration>
<testSuiteProperties>
<properties>
<property>PropertyCode=${propertyCode}</property>
<property>Environment=${environment}</property>
<Gateway>Gateway=${gateway}</Gateway>
</properties>
</testSuiteProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>`
My tests need to have dependency plugin redfish as it supports soapuiTestSuite properties configuration.
Now when I tried to run this mvn install test, the build starts to run with first plugin and fails as it doesn't have second plugin downloaded and later runs again downloading second but fails. I need to have both the plugins and whole configuration setup before I run the goal.
I am new to Maven structure.
Add execute at the second plugin.
For example, if you want to execute maven-soapui-extension-plugin before soapui-pro-maven-plugin you can add this execution:
<executions>
<execution>
<id>soapui-tests</id>
<phase>verify</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
And just do 'mvn install', because you have executions attached to default Maven lifecycle.
Look at the list of default Maven Lifecycle in the execution order: validate, initialize, .. deploy (docs here).

Importing custom classes in jrxml and compiling with maven plugin

I have to import few custom Java classes in JasperReports's JRXML file.
I am able to do that using
<import value="org.ga.jasper.sample.MyCustomClass"/>
This works perfectly fine and I am able to run this jrxml and test my code.
Problem comes when I want to precompile this into .jasper file by using jasperreports-maven-plugin.
When doing a build, it complains saying it does not find my package and hence import is invalid.
package org.ga.jasper.sample does not exist
import org.ga.jasper.sample.MyCustomClass;
FYI, My Java code and .jrxml are in the same maven module but in different folders.
Following is the code from my plugin tag
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/main/resources/jasper</sourceDirectory>
<outputDirectory>${project.build.directory}/jasper</outputDirectory>
<compiler>net.sf.jasperreports.engine.design.JRJavacCompiler</compiler>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.5.1</version>
</dependency>
</dependencies>
</plugin>
By default, the plugin runs in the generate-resources phase, before the current module's classes have been compiled. You can change the plugin to run at the compile phase instead. See notes at bottom of page here:
http://mojo.codehaus.org/jasperreports-maven-plugin/usage.html
Also, see this similar q/a:
Compile JasperReports jrxml with scriptlet dependency in same project via Maven
This is how I solved the issue. Adding phase
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/main/resources/jasper</sourceDirectory>
<outputDirectory>${project.build.directory}/jasper</outputDirectory>
<compiler>net.sf.jasperreports.engine.design.JRJavacCompiler</compiler>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.5.1</version>
</dependency>
</dependencies>
</plugin>

jaxws-maven-plugin wsgen on test endpoint

I'm trying to get maven 3 to run wsgen against two web service endpoints. One is a 'production' endpoint, located under src/main/java, and the other is a 'test' endpoint that is located under src/test/java.
The problem is, wsgen does not find the 'test' sei class as (presumably) it only has src/main/java on the classpath. It is not possible to directly set the wsgen classpath using jaxws-maven-plugin (there's no config element for it). I've tried binding to the generate-test-sources phase but no joy
Here's the pom snippet:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<!-- this works fine -->
<execution>
<id>Production</id>
<configuration>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
<protocol>soap1.1</protocol>
<sei>com.foo.ws.ProductionEndPoint</sei>
<sourceDestDir>${project.build.directory}/jaxws/wsgen/src</sourceDestDir>
<destDir>${project.build.directory}/jaxws/wsgen/classes</destDir>
<packageName>com.foo.ws</packageName>
</configuration>
<goals>
<goal>wsgen</goal>
</goals>
</execution>
<!-- this fails with Class Not Found on the sei class -->
<execution>
<phase>generate-test-sources</phase>
<id>Test</id>
<configuration>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
<protocol>soap1.1</protocol>
<sei>com.foo.ws.TestEndPoint</sei>
<sourceDestDir>${project.build.directory}/jaxws/wsgen/src</sourceDestDir>
<destDir>${project.build.directory}/jaxws/wsgen/classes</destDir>
<packageName>com.foo.ws.test</packageName>
</configuration>
<goals>
<goal>wsgen</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.4</version>
</dependency>
</dependencies>
</plugin>
</plugin>
</build>
You should bind to the process-test-classes phase
Instead of
<phase>process-test-classes</phase>
It should be
<phase>process-test-classes</phase>

Categories

Resources