0

使用.jrxml创建JasperReports报告,我的 Java 代码是:

package jasperReport.Testreport;

import java.io.*;
import java.util.*;
import java.sql.Connection;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.export.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class App {

    public static void main(String[] args) {

        try {
            InputStream input;
            Class.forName("com.mysql.jdbc.Driver");

            Connection connection;
            JasperReport report;
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/jasper", "root", "root");
            JasperPrint jasperPrint;
            HashMap jasperParameter = new HashMap();
            report = JasperCompileManager.compileReport("sample_report.jrxml");
            jasperPrint = JasperFillManager.fillReport(report, jasperParameter, connection);
            JasperExportManager.exportReportToPdfFile(jasperPrint, "sample_report.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

使用POM.xml

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>

    <dependency>
        <groupId>tomcat</groupId>
        <artifactId>jasper-compiler-jdt</artifactId>
        <version>5.5.23</version>
    </dependency>

    <dependency>
        <groupId>tomcat</groupId>
        <artifactId>jasper-runtime</artifactId>
        <version>5.5.23</version>
    </dependency>

    <dependency>
        <groupId>javax.jcr</groupId>
        <artifactId>jcr</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>3.7.5</version>
    </dependency>

    <dependency>
        <groupId>jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>1.2.6</version>
    </dependency>

    <dependency>
        <groupId>commons-digester</groupId>
        <artifactId>commons-digester</artifactId>
        <version>1.8</version>
    </dependency>

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.0</version>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.8.0</version>
    </dependency>

    <dependency>
        <groupId>com.lowagie</groupId>
        <artifactId>itext</artifactId>
        <version>2.1.0</version>
    </dependency>

    <dependency>
        <groupId>tomcat</groupId>
        <artifactId>jasper-compiler-jdt</artifactId>
        <version>5.5.23</version>
    </dependency>
</dependencies>

我尝试使用各种版本导入Digester jar ,但没有任何效果。

当我将其作为 Maven 项目执行时,它可以正常工作。当我尝试将其转换为 OSGI 捆绑包时,我收到错误消息

Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Digester not found by       com.thermo.wcm.web.jasperReport 

这里是否需要进行其他更正?

4

1 回答 1

0

此问题已使用

   <Export-Package> org.apache.commons.digester.* </Export-Package> 

在 OSGI 配置的 pom.xml 中

于 2013-07-11T19:27:00.220 回答