0

I am currently trying to make exe using launch4j to generate reports using the jasper. When I run the runnable jar, it is perfectly showing. But when I run the exe file, I always get an exception related to the jar dependencies. I have shown the jre folder while creating exe by launch4j. Despite this, I add the following jars file into my build path,

  • jasperreports-5.6.0.jar
  • commons-logging-1.1.jar
  • commons-beanutils-1.8.2.jar
  • commons.digester-2.1.jar
  • commons-collections-3.2.1.jar
  • groovy-all-2.0.1.jar
  • jdt-compiler-3.1.1.jar
  • jfreechart-1.0.12.jar
  • jcommon-1.0.15.jar
  • iText-2.1.7.js2.jar

the program generates me class not found exception either related with collections. My main goal is via using jrxml file to generate a report. I am using iReport 5.6.0 to generate jrxml file. Any help is appreciated. The Stack trace of error is below;

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JRDataSource
at shg.da.com.MainFrame.<init>(MainFrame.java:63)
at shg.da.com.MainFrame$1.run(MainFrame.java:41)
at java.awt.event.InvocationEvent.dispatch(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.doIntersectionPrivilege(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) 
Caused by: java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JRDataSource
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 16 more

My coding are as follows:

package shg.da.com;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.swing.JRViewer;

public class MainFrame extends JFrame {

    private JPanel contentPane;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                MainFrame frame = new MainFrame();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public MainFrame() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);
    
    JButton vouPrintButton = new JButton("Print");
    
    vouPrintButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {             
            
            try {
                List<Map<String,?>> datasource = new ArrayList<Map<String,?>>();
                
                Map<String, Object> m;
                
                    m = new HashMap<String, Object>();
                    m.put("zorg",880022);
                    m.put("xvoucher", "JV--005282/2017");
                    m.put("xdate", "2021-07-03");
                    datasource.add(m);

                JRDataSource jrDataSource = new JRBeanCollectionDataSource(datasource);
                String sourceName = "glv.jrxml";
                JasperReport report = JasperCompileManager.compileReport(sourceName);
                JasperPrint filledReport =  JasperFillManager.fillReport(report, null, jrDataSource) ;
                JFrame rptFrame = new JFrame(); 
                
                rptFrame.getContentPane().add(new JRViewer(filledReport));
                rptFrame.pack();
                rptFrame.setVisible(true);
            }catch(Exception e) {
                e.printStackTrace();
            }
        }
    });
    contentPane.add(vouPrintButton);
}

}

running the jar from command prompt

running the exe from command prompt

  • 1
    So it sounds like launch4j is not including the Jasper classes. btw, do you know that JDKs now support making installers out of the box? – g00se Jul 06 '21 at 16:17
  • @g00se, may be. But I went through a number of tutorial where building exe from launch4j have been shown. I did exactly the same way. I did not try with JDKs to make a installer. – Chistia Chowdhury Jul 07 '21 at 07:22
  • I might be able to help. [This](https://technojeeves.com/index.php/aliasjava1/111-making-native-installable-apps-with-java-9) is module-oriented but this approach can be tweaked for your case with jars: – g00se Jul 07 '21 at 09:35

0 Answers0