【问题标题】:Jasper reports HtmlComponent class not foundJasper 报告 HtmlComponent 类未找到
【发布时间】:2015-09-18 09:10:13
【问题描述】:

我通过使用 iReport 放置 HTML 调色板设计了一个简单的报告。当我运行报告时,我得到了这个异常:

原因:java.lang.ClassNotFoundException: net.sf.jasperreports.components.html.HtmlComponent from [Module "deployment.myProject.war:main" from Service Module Loader]

我正在使用此代码。

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);
}

我在这一行遇到了异常:

jReport = (JasperReport) JRLoader.loadObject(is);

查看了jasperReports.jar,发现没有htmlComponent类。我还使用最新版本的 jasperReport 库(即 6.1.0)并且没有 net.sf.jasperreports.components。 html.HtmlComponent 类在里面。任何人都请帮助我如何使用 netbeans 将它们包含到我的项目中???

编辑 1: 我已使用以下代码将 htmlComponent jar 作为 pom.xml 文件中的依赖项包含到我的 maven Web 项目中:

     <dependency>
     <groupId>net.sf.jasperreports</groupId>
     <artifactId>htmlcomponent</artifactId>
     <scope>system</scope>
     <version>1.0</version>
     <systemPath>${basedir}/src/lib/htmlcomponent.jar</systemPath>
     </dependency>

现在我的依赖结构如下所示:

可以看到 htmlComponent 依赖包含 net.sf.jasperreports.components.html.HtmlComponent 类。但我仍然遇到同样的错误。请帮忙。

【问题讨论】:

  • 请给你看jrxml

标签: java jasper-reports


【解决方案1】:

你必须添加 htmlcomponent.jar

检查这个以建立htmlcomponent.jar

同时检查this

【讨论】:

  • 感谢您的回复。我创建了 htmlComponent.jar 并将其包含在我的项目中。我的项目是 Maven 网络项目。所以我将本地系统中的这个 jar 文件作为依赖项包含在 pom.xml 文件中。代码是: net.sf.jasperreportshtmlcomponentsystem1.0${basedir}/ src/lib/htmlcomponent.jar 和 htmlComponent 已成功添加为我的项目中的依赖项。但我仍然遇到相同的异常。
  • 试过 Maven->更新项目并清理项目并从 IDE 重新启动应用程序?
  • 将依赖范围从 provided 更改为 compile 并试一试
  • 我正在使用 system 因为我使用本地系统中的 htmlComponent.jar。查看我的依赖代码。如果我在该代码中做错了,请更新。我更新了本教程以添加外部依赖tutorialspoint.com/maven/maven_external_dependencies.htm
【解决方案2】:

我在 pom.xml 文件中添加了以下依赖项。

    <dependency>
        <groupId>htmlComponent</groupId>
        <artifactId>htmlComponent</artifactId>
        <version>1.0</version>
    </dependency>

然后按照链接Guide to installing 3rd party JARs中描述的命令在项目中安装第3方jar

mvn install:install-file -Dfile=htmlcomponent.jar -DgroupId=htmlComponent -DartifactId=htmlComponent -Dversion=1.0 -Dpackaging=jar.

然后构建项目,问题就解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 2023-03-30
    相关资源
    最近更新 更多