1

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:

enter image description here

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.

saurabh
  • 209
  • 1
  • 4
  • 17

2 Answers2

4

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.

saurabh
  • 209
  • 1
  • 4
  • 17
1

You have to add htmlcomponent.jar

Check this for building htmlcomponent.jar

Also check this.

Community
  • 1
  • 1
Arasu
  • 2,078
  • 6
  • 40
  • 67
  • Thanks for your reply. I have created the htmlComponent.jar and include it in my project . My project is maven web project. So i include this jar file from local system as dependency in pom.xml file. code is : net.sf.jasperreports htmlcomponent system 1.0 ${basedir}/src/lib/htmlcomponent.jar and htmlComponent is successfully added as dependency in my project .But i still getting the same exception. – saurabh Jul 01 '15 at 10:55
  • tried Maven->Update Project and clean project and re-launch the application from the IDE? – Arasu Jul 01 '15 at 10:59
  • change dependency scope from provided to compile and give it a try – Arasu Jul 01 '15 at 12:03
  • check http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope – Arasu Jul 01 '15 at 12:05
  • I am using system because i use htmlComponent.jar from my local system. See my dependency code .Please update if i did wrong in that code. I refrred this tutorial for adding external dependency http://www.tutorialspoint.com/maven/maven_external_dependencies.htm – saurabh Jul 01 '15 at 12:10
  • this might http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html help you – Arasu Jul 01 '15 at 12:15
  • thanks for these links i tried that but i need repository from which to download jar. For eg http:// .Any idea of repository. – saurabh Jul 02 '15 at 03:46
  • An artifact you mention in pom is actually downloaded from repository. If you are using eclipse maven then it probably inside /Users//.m2 if you want to explicit go to a certain repository you use the mentioned tags. refer http://www.mkyong.com/maven/how-to-add-remote-repository-in-maven-pom-xml/ – Arasu Jul 02 '15 at 03:55