supun151515 Posted February 17, 2015 Share Posted February 17, 2015 Hello Friends,Good day!,I have created jasper report inside Eclipse Luna java project.. I have imported all the jar files in 'jasperreports-6.0.0lib' and 'jasperreports-6.0.0dist'.But when I export Executable Jar file, it will become more than 50MB file. Also report.jrxml file has not included on it.I have three questions;1. What are the exact Jasper jar files to import in Eclipse??2. How can I include report.jrxml file inside my exported Jar file. It should be secure and user should not able to edit the report3. How can I display Jasper View inside java swing window object (not a separate window)?4. What is the proper way to deploy the project with user-non editable package (related to 2nd question)?Below is my code;form1.javapackage jasper1;import jasper1.DB.database;import java.awt.EventQueue;import java.sql.Connection;import javax.swing.JFrame;import javax.swing.JButton;import javax.swing.JOptionPane;import javax.swing.JTextField;import javax.swing.JLabel;import net.sf.jasperreports.engine.JRException;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.view.JasperViewer;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;public class form1 { private JFrame frame; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { form1 window = new form1(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } Connection conn = null; private JTextField text_Host; private JTextField text_DB; private JTextField text_User; private JTextField text_Pwd; /** * Create the application. */ public form1() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JButton btnNewButton = new JButton("Connect"); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { btnNewButton.setText("Please wait..."); } @Override public void mouseReleased(MouseEvent e) { btnNewButton.setText("Connect"); } }); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { database.host = text_Host.getText(); database.db = text_DB.getText(); database.user = text_User.getText(); database.pwd = text_Pwd.getText(); conn = DB.Connector(); if(conn != null){ //JOptionPane.showMessageDialog(null, "Successfully Connected"); String reportPath = "reports/report.jrxml"; try { JasperReport jr = JasperCompileManager.compileReport(reportPath); //JOptionPane.showMessageDialog(null, conn); JasperPrint jp = JasperFillManager.fillReport(jr, null, conn); JasperViewer.viewReport(jp); conn.close(); } catch (Exception e1) { JOptionPane.showMessageDialog(null, e1.getMessage()); } return; } } }); btnNewButton.setBounds(73, 167, 130, 23); frame.getContentPane().add(btnNewButton); text_Host = new JTextField(); text_Host.setText("localhost"); text_Host.setBounds(93, 32, 110, 20); frame.getContentPane().add(text_Host); text_Host.setColumns(10); text_DB = new JTextField(); text_DB.setText("qatarclean"); text_DB.setBounds(93, 63, 110, 20); frame.getContentPane().add(text_DB); text_DB.setColumns(10); text_User = new JTextField(); text_User.setText("root"); text_User.setBounds(93, 94, 110, 20); frame.getContentPane().add(text_User); text_User.setColumns(10); text_Pwd = new JTextField(); text_Pwd.setText("supun123"); text_Pwd.setBounds(93, 125, 110, 20); frame.getContentPane().add(text_Pwd); text_Pwd.setColumns(10); JLabel lblHost = new JLabel("Host"); lblHost.setBounds(38, 31, 46, 23); frame.getContentPane().add(lblHost); JLabel lblDatabase = new JLabel("Database"); lblDatabase.setBounds(38, 63, 56, 20); frame.getContentPane().add(lblDatabase); JLabel lblUserName = new JLabel("User Name"); lblUserName.setBounds(38, 94, 67, 23); frame.getContentPane().add(lblUserName); JLabel lblPassword = new JLabel("Password"); lblPassword.setBounds(38, 125, 56, 20); frame.getContentPane().add(lblPassword); }}[/code]DB.javapackage jasper1;import java.sql.Connection;import java.sql.DriverManager;import javax.swing.JOptionPane;public class DB { Connection conn = null; public static class database { public static String host; public static String db; public static String user; public static String pwd; } public static Connection Connector(){ try{ Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://"+database.host+":3306/" +database.db ,database.user,database.pwd); return conn; } catch (Exception e){ JOptionPane.showMessageDialog(null, "Login Failed.n" + e); return null; } }}[/code] Thank You,Supun Link to comment Share on other sites More sharing options...
Solution al881 Posted February 17, 2015 Solution Share Posted February 17, 2015 I can only speak from integrating JBOSS 5.1 and Jasper Reports 4+ The files I included were jasperreports-4.0.2.jar jasperreports-fonts-4.0.2.jar jasperreports-javaflow-4.0.2.jar We build simple templates (.jrxml) and compile to .jasper files. You package the .jasper files into your WAR file or whatever your deployment file is.Then in your JAVA code, you marry the correct .jasper file to the data you pull from the DB to produce the report.Depending on how large the data is to use for the report, your user experience will be somewhat uncomfortable.Example,let's say the data is 100,000 records of "something". When you transform the data to the report, it will take some time so you need to prep the user to understand this.Here is the flow of what we do:1. User selects an operation that allows them to pull data back. Usually date driven.2. This data is displayed in a table (JSP type form )3. Below this table are icons to generate or export a Jasper PDF or Excel report.4. User clicks the icon, which goes to another form that informs user that report may take some time. User presses button to confirm or abort.5. Then pop up a small window informing "report being generated or ????" Al Link to comment Share on other sites More sharing options...
supun151515 Posted February 18, 2015 Author Share Posted February 18, 2015 I need help with above 2nd and 3rd questions please Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now