Issue
I have a Netbeans Maven Java project in which I use Jasper reports. While in Netbeans everything works good, but when I run my jar with dependencies file program works until i try to get report with data from database. When I press button to return data in report between two dates program throws error - Exception in thread "AWT-EventQueue-0" Exception: net.sf.jasperreports.engine.JRRuntimeException thrown from the UncaughtExceptionHandler in thread "AWT-EventQueue-0". When I try to get data from list (showMessageDialog), that I got from DB everything works OK. I create my jar file with shade plugin. I have added POM file code. I see only "net.sf.jasper2docx", but no other jasper dependencies. Maybe problem is with dependencies declaration in POM? In project dependencies I have jasper2docx-apache-poi, jasper2docx-api and jasperreports-6.1.0 jars.
CLASS CODE
import beans.Spent;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.builder.DynamicReports;
import net.sf.dynamicreports.report.builder.column.Columns;
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.constant.VerticalTextAlignment;
import net.sf.dynamicreports.report.definition.datatype.DRIDataType;
import org.hibernate.Query;
import org.hibernate.Session;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
searchDate();
}
private void searchDate() {
if ((jDateChooser1.getDate() == null) || (jDateChooser2.getDate() == null)) {
JOptionPane.showMessageDialog(rootPane, "Error text");
} else {
Date dataFrom = jDateChooser1.getDate();
Date dataTo = jDateChooser2.getDate();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String dataF = format.format(dataFrom);
String dataT = format.format(dataTo);
Date dateNow = new Date();
String dataDabar = format.format(dateNow);
Session session;
session = HibernateUtil.getSessionFactory().openSession();
try {
String hql2 = "FROM Spent E WHERE E.date BETWEEN '" + dataF + "' AND '" + dataT + "' ORDER BY E.date";
Query query = session.createQuery(hql2);
List<Spent> spentList= query.list();
StyleBuilder boldStyle = DynamicReports.stl.style().bold();
StyleBuilder centerStyle = DynamicReports.stl.style().setTextAlignment(HorizontalTextAlignment.CENTER,
VerticalTextAlignment.MIDDLE);
StyleBuilder leftStyle = DynamicReports.stl.style().setTextAlignment(HorizontalTextAlignment.LEFT, VerticalTextAlignment.JUSTIFIED);
JasperReportBuilder report = DynamicReports.report();
TextColumnBuilder<String> colName = Columns.column("Title", "name",
DynamicReports.type.stringType());
TextColumnBuilder<Date> colDate = Columns.column("Date", "date", (DRIDataType) DynamicReports.type.dateType());
TextColumnBuilder<Double> colPrice = Columns.column("Price", "price",
DynamicReports.type.doubleType()).setPattern("#,##0.00");
TextColumnBuilder<String> colCat = Columns.column("Category", "cat",
DynamicReports.type.stringType());
TextColumnBuilder<String> colComments = Columns.column("Comments", "comm",
DynamicReports.type.stringType());
report.setDataSource(spentList)
.columns(colDate.setWidth(30).setStyle(centerStyle), colName.setWidth(70), colPrice.setWidth(20), colCat.setWidth(35), colComments)
.show(false);
} catch (Exception ex) {
JOptionPane.showMessageDialog(rootPane, ex.getLocalizedMessage(), "Klaida", JOptionPane.PLAIN_MESSAGE);
} finally {
session.close();
}
}
POM.XML
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>Finansa</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
</dependency>
<dependency>
<groupId>net.sourceforge.dynamicreports</groupId>
<artifactId>dynamicreports-core</artifactId>
<version>4.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>net.sf.jasper2docx</groupId>
<artifactId>jasper2docx-apache-poi</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>com.toedter</groupId>
<artifactId>jcalendar</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>main.Login</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>create-my-bundle</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>main.Login</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
PRINTSTACKTRACE
Exception in thread "AWT-EventQueue-0" Exception in thread "AWT-EventQueue-0"
Exception: net.sf.jasperreports.engine.JRRuntimeException thrown from the Uncaug
htExceptionHandler in thread "AWT-EventQueue-0"
java.lang.NullPointerException
at net.sf.dynamicreports.jasper.base.JasperChartCustomizer.customize(Jas
perChartCustomizer.java:42)
at net.sf.jasperreports.engine.fill.JRFillChart.evaluateChart(JRFillChar
t.java:861)
at net.sf.jasperreports.engine.fill.JRFillChart.evaluateRenderer(JRFillC
hart.java:819)
at net.sf.jasperreports.engine.fill.JRFillChart.evaluate(JRFillChart.jav
a:808)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFi
llElementContainer.java:258)
at net.sf.jasperreports.engine.fill.JRFillFrame.evaluate(JRFillFrame.jav
a:163)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFi
llElementContainer.java:258)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:
454)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummaryNoLastFo
oterSamePage(JRVerticalFiller.java:1071)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummary(JRVerti
calFiller.java:1032)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportEnd(JRVer
ticalFiller.java:293)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVertic
alFiller.java:129)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
551)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFill
er.java:411)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:122)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.
java:667)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillMa
nager.java:983)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperPrin
t(JasperReportBuilder.java:312)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.show(JasperR
eportBuilder.java:336)
at main.SData.searchDate(SData.java:203)
at main.SData.jButton1ActionPerformed(SData.java:102)
at main.SData.access$000(SData.java:29)
at main.SData$1.actionPerformed(SData.java:60)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Solution
Solution found by OP:
There must be added Jasper reports plugin dependency. Without it Jasper reports will not work at 100%.
<dependency> <groupId>com.alexnederlof</groupId> <artifactId>jasperreports-plugin</artifactId> <version>2.0</version> </dependency>
Answered By - Jongware
Answer Checked By - Mildred Charles (JavaFixing Admin)