动态报告(5.0)没有显示来自eclipse和jar文件的相同报告

时间:2017-01-30 10:12:34

标签: java eclipse maven jasper-reports dynamic-reports

当我生成关于eclipse的报告时,没有任何问题。但是,当我从单个jar文件运行它时,它给了我错误的报告。标题未显示vs vs.

当我从Eclipse运行应用程序时,它会生成如下报告:

working on eclipse

当我从jar文件运行它时,它如下

working from jar file

我的报告生成代码如下

import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.stl;
import static net.sf.dynamicreports.report.builder.DynamicReports.type;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.ozpas.entity.mikro.XozIslemGunKumulatif;
import com.ozpasentegre.controller.Loghelper;
import com.ozpasentegre.model.UtilModel;

import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.builder.DynamicReports;
import net.sf.dynamicreports.report.builder.column.TextColumnBuilder;
import net.sf.dynamicreports.report.builder.style.StyleBuilder;
import net.sf.dynamicreports.report.constant.HorizontalTextAlignment;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import ozpasyazilim.util.UtilDate;


public class ReportIslemGunToplamlari {

    List<XozIslemGunKumulatif> data;

    public static void main(String[] args) {

        new ReportIslemGunToplamlari().build();

    }

    public void build() {

        StyleBuilder boldStyle = stl.style().bold();
        StyleBuilder boldCenteredStyle = stl.style(boldStyle).setHorizontalTextAlignment(
            HorizontalTextAlignment.CENTER);
        //      StyleBuilder columnTitleStyle = stl.style(boldCenteredStyle).setBorder(stl.pen1Point()).setBackgroundColor(
        //          Color.LIGHT_GRAY);



        TextColumnBuilder<Double> meblagColumn = col.column("Mikro Tutar", "dblguntoplami_reel", type.doubleType())
            .setFixedWidth(75).setPattern("#.00");

        //      TextColumnBuilder<Double> bankaColumn = col.column("Banka Tutar", "dblguntoplami_reel", type.doubleType())
        //          .setFixedWidth(75).setPattern("#.00");

        TextColumnBuilder<Date> dateColumn = col.column("Tarih", "dateislem", type.dateType())
            .setHorizontalTextAlignment(HorizontalTextAlignment.LEFT).setFixedWidth(75);
        TextColumnBuilder<Integer> rowNumberColumn = col.reportRowNumberColumn("No.")
            //sets the fixed width of a column, width = 2 * character width
            .setFixedColumns(2).setHorizontalTextAlignment(HorizontalTextAlignment.CENTER);

        try {

            JasperReportBuilder report = DynamicReports.report();//a new report

            // locale etki etmiyor, format factory eklendi
            //          report.setLocale(new Locale("tr", "TR"));
            report.setParameter(JRParameter.REPORT_FORMAT_FACTORY, new FormatFactory());

            // rapor düzenleri

            //          report.setColumnTitleStyle(columnTitleStyle).highlightDetailEvenRows();

            //add columns
            report.title(cmp.text(" Günlük İşlem Toplamları "));

            report.columns(dateColumn, meblagColumn);

            //          .setStyle(boldCenteredStyle));//shows report title

            report.setDataSource(createDataSource());//set datasource

            report.pageFooter(cmp.pageXofY().setStyle(boldCenteredStyle));//shows number of page at page footer

            //          report.summary(cmp.text("Rapor Sonu").setStyle(boldCenteredStyle));

            report.setShowColumnTitle(true);
            report.setSummaryWithPageHeaderAndFooter(true);

            report.show(false);//create and show report

            //export the report to a pdf file
            //          report.toPdf(new FileOutputStream("report.pdf"));

        } catch (DRException e) {
            Loghelper.logexceptionMessageMail("Hata :" + UtilModel.exceptiontostring(e));
            //e.printStackTrace();
        }
        //      catch (FileNotFoundException e) {
        //          Loghelper.logexceptionMessageMail("Hata :" + UtilModel.exceptiontostring(e));
        //      }



    }

    private JRDataSource createDataSource() {

        if (data == null) {

            data = new ArrayList<>();

            XozIslemGunKumulatif obj1 = new XozIslemGunKumulatif();
            obj1.setDblguntoplami(101.20D);
            obj1.setDateislem(UtilDate.stringToDate_yyyymmddformati("20170501"));

            data.add(obj1);

            XozIslemGunKumulatif obj2 = new XozIslemGunKumulatif();
            obj2.setDblguntoplami(105.20D);
            obj2.setDateislem(UtilDate.stringToDate_yyyymmddformati("20170502"));

            data.add(obj2);
        }

        return new JRBeanCollectionDataSource(data);

    }

    public List<XozIslemGunKumulatif> getData() {
        return data;
    }

    public void setData(List<XozIslemGunKumulatif> data) {
        this.data = data;
    }



}

我的实体如下

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.*;
import java.util.Date;


/**
 * The persistent class for the XozIslemGunKumulatif database table.
 * 
 */
@Entity
@Table(name = "XozIslemGunKumulatif")
//@NamedQuery(name="XozIslemGunKumulatif.findAll", query="SELECT x FROM XozIslemGunKumulatif x")
public class XozIslemGunKumulatif implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(unique = true, nullable = false) // konulmasa da olur örnek olsun diye konuld
    private Integer id;

    @Column(nullable = false)
    private Integer idislemtip;

    @Column(nullable = false)
    private Date dateislem;

    @Column(precision = 17, scale = 5)
    private BigDecimal dblguntoplamionayli;

    private Boolean bitOnayli;

    private Integer idKullanici;

    private Date datechanged;

    private Date datecreated;

    @Transient
    private Double dblguntoplami;

    @Transient
    private Double dblguntoplami_reel;

    @Transient
    private Boolean bitsecim;

    // getter and setters

    public Boolean getBitsecim() {
        return bitsecim;
    }

    public void setBitsecim(Boolean bitsecim) {
        this.bitsecim = bitsecim;
    }

    public Double getDblguntoplami_trans() {
        return dblguntoplami_reel;
    }

    public void setDblguntoplami_trans(Double dblguntoplami_trans) {
        this.dblguntoplami_reel = dblguntoplami_trans;
    }

    public XozIslemGunKumulatif() {
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getDatechanged() {
        return this.datechanged;
    }

    public void setDatechanged(Date datechanged) {
        this.datechanged = datechanged;
    }

    public Date getDatecreated() {
        return this.datecreated;
    }

    public void setDatecreated(Date datecreated) {
        this.datecreated = datecreated;
    }

    public Double getDblguntoplami() {
        return this.dblguntoplami;
    }

    public void setDblguntoplami(Double dblguntoplami) {
        this.dblguntoplami = dblguntoplami;
    }

    public Integer getIdislemtip() {
        return this.idislemtip;
    }

    public void setIdislemtip(Integer idislemtip) {
        this.idislemtip = idislemtip;
    }

    public Integer getIdkullanici() {
        return this.idKullanici;
    }

    public void setIdkullanici(Integer idkullanici) {
        this.idKullanici = idkullanici;
    }

    public BigDecimal getDblguntoplamionayli() {
        return dblguntoplamionayli;
    }

    public void setDblguntoplamionayli(BigDecimal dblguntoplamionayli) {
        this.dblguntoplamionayli = dblguntoplamionayli;
    }

    public Double getDblguntoplami_reel() {
        return dblguntoplami_reel;
    }

    public void setDblguntoplami_reel(Double dblguntoplami_reel) {
        this.dblguntoplami_reel = dblguntoplami_reel;
    }

    public Date getDateislem() {
        return dateislem;
    }

    public void setDateislem(Date dateislem) {
        this.dateislem = dateislem;
    }

    public Boolean getBitOnayli() {
        return bitOnayli;
    }

    public void setBitOnayli(Boolean bitOnayli) {
        this.bitOnayli = bitOnayli;
    }

}

我的动态报告maven依赖关系如下。

<dependency>
        <groupId>net.sourceforge.dynamicreports</groupId>
        <artifactId>dynamicreports-core</artifactId>
        <version>5.0.0</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.dynamicreports</groupId>
        <artifactId>dynamicreports-adhoc</artifactId>
        <version>5.0.0</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.dynamicreports</groupId>
        <artifactId>dynamicreports-googlecharts</artifactId>
        <version>5.0.0</version>
    </dependency>

我的操作系统是Windows 10.我使用程序集生成单个jar文件:maven的单个插件。 Java版本是8

0 个答案:

没有答案