Environment:
I try to execute a method in Commons modul from Front modul. Front module does not have jasper report dependency and execute a method from Commons modul that it uses jasper report library.
It is a migration from Jboss5.2 and it worked properly, but with Jboss7.2 I have some issues.
When I try to execute ReportManager methods (common module) from Front module it throws a java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JRException
Any idea why is that?
Front Modul pom.xml
<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>
<parent>
<groupId>es.new.for</groupId>
<artifactId>for2</artifactId>
<version>8.0.0</version>
</parent>
<artifactId>for-front</artifactId>
<packaging>war</packaging>
<name>for-front</name>
<dependency>
<groupId>es.new.for</groupId>
<artifactId>for-commons</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>es.new.for</groupId>
<artifactId>for-ejb</artifactId>
<scope>provided</scope>
</dependency>
<!--No dependency to jasperreport-->
...
Commons Modul pom.xml
<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">
<parent>
<groupId>es.new.for</groupId>
<artifactId>for2</artifactId>
<version>8.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>for-commons</artifactId>
<packaging>jar</packaging>
<name>for-commons</name>
...
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>4.0.0</version>
</dependency>
...
ReportManager.java (Commons module)
public class ReportManager { ... public static byte[] compilaReport(byte[] report) throws AppException { try { log.info("Compila"); ByteArrayInputStream inputStream = new ByteArrayInputStream(report);
JasperReport compiled = JasperCompileManager.compileReport(inputStream);
return SerializationUtils.serialize(compiled);
} catch (Exception e) {
log.error("compile report", e);
throw new AppException("InformeService.compile: Problem with compiling report", new AppException("Report compile error", e));
}
}
...
ExecutarInformeBean.java (Front module)
public void compileReport(Informe informe, Map<String, Object> parametresSend) {
if (informe != null) {
try {
if (parametresSend == null)
parametresSend = new HashMap<>();
// añadimos subinformes
List<Parametre> parametres = informe.getParametres();
for (Parametre parametre : parametres) {
if (parametre.getTipus().equalsIgnoreCase("SUBINFORME")) {
try {
if (parametre.getSubInformeCompilado() == null) {
** parametre.setSubInformeCompilado(ReportManager.compilaReport(parametre.getSubInformeOriginal()));//Exeption java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JRException
}
** ReportManager.addParameter(parametresSend, parametre); //Exeption java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JRException
} catch (AppException e) {
log.error("compileReport subinforme", e);
} catch (Exception e) {
log.error("compileReport subinforme", e);
}
}
}
...
Error
13:36:57,311 SEVERE [org.primefaces.application.exceptionhandler.PrimeExceptionHandler] (default task-1) net/sf/jasperreports/engine/JRException: java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JRException
at deployment.for2.ear.for-front.war//es.new.for.presentation.front.informe.ExecutarInformeBean.compileReport(ExecutarInformeBean.java:200)
at deployment.for2.ear.for-front.war//es.new.for.presentation.front.informe.ExecutarInformeBean.executaReportDirecte(ExecutarInformeBean.java:134)
at deployment.for2.ear.for-front.war//es.new.for.presentation.front.informe.ExecutarInformeBean.reportDirecto(ExecutarInformeBean.java:74)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
You declared the scope to be provided
which means that the artifact is not packaged into the EAR.
If it is not provided in any other way, calling the JAR will fail.