Reputation: 209
I have designed a simple report by putting HTML palette using iReport. When I run the report i get this exception:
Caused by: java.lang.ClassNotFoundException: net.sf.jasperreports.components.html.HtmlComponent from [Module "deployment.myProject.war:main" from Service Module Loader]
I am using this code.
InputStream is;
JasperReport jReport = null;
JasperPrint jPrint = null;
if (Utils.isEmpty(dataList)) {
throw new Exception("No data to fill");
}
try {
is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/templates/jr/myfile.jasper");
if (is != null) {
jReport = (JasperReport) JRLoader.loadObject(is);
}
if (jReport != null) {
if ("JDBC".equalsIgnoreCase(dataSrc)) {
Connection con = ((DataSource) (new InitialContext().lookup(""))).getConnection();
jPrint = JasperFillManager.fillReport(jReport, params, con);
} else if ("JAVABEAN".equalsIgnoreCase(dataSrc)) {
JRBeanCollectionDataSource jrDataSource = new JRBeanCollectionDataSource(dataList);
jPrint = JasperFillManager.fillReport(jReport, params, jrDataSource);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
throw new Exception("Error generating JR Template:" + templateName, e);
}
I got exception in this line :
jReport = (JasperReport) JRLoader.loadObject(is);
I have checked the jasperReports.jar and found that there is no htmlComponent class. I also use latest version of jasperReport library(i.e 6.1.0) and there is no net.sf.jasperreports.components. html.HtmlComponent class in it. Anyone please help me how to include them into my project with netbeans ???
EDIT 1 : I have included the htmlComponent jar into my maven web project as dependency in pom.xml file using this code:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>htmlcomponent</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}/src/lib/htmlcomponent.jar</systemPath>
</dependency>
Now my dependency structure looks like this:
You can see the htmlComponent dependency contains the net.sf.jasperreports.components.html.HtmlComponent class. But i am still getting the same error. Please help.
Upvotes: 1
Views: 7268
Reputation: 209
I have added following dependency into pom.xml file.
<dependency>
<groupId>htmlComponent</groupId>
<artifactId>htmlComponent</artifactId>
<version>1.0</version>
</dependency>
and then install 3rd party jar in project by following command as describe in this link Guide to installing 3rd party JARs
i.e
mvn install:install-file -Dfile=htmlcomponent.jar -DgroupId=htmlComponent -DartifactId=htmlComponent -Dversion=1.0 -Dpackaging=jar.
and then build the project and the problem is resolved.
Upvotes: 4
Reputation: 2148
You have to add htmlcomponent.jar
Check this for building htmlcomponent.jar
Also check this.
Upvotes: 1