denisputnam Posted June 24, 2016 Share Posted June 24, 2016 I am trying to use the jasperreports library in a plain java application. It won't compile because it can't find the aegean chart theme. Can someone point me to a simple example of how to get a .jrxml file to compile and pass this theme to the JasperCompileManager?This is my code below:.package com.asset.jasper.mvc.reports;import java.io.File;import java.io.IOException;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.util.HashMap;import java.util.Map;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import java.sql.PreparedStatement;import net.sf.jasperreports.engine.JRDataSource;//import net.sf.jasperreports.engine.JREmptyDataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRResultSetDataSource;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperExportManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.chartthemes.simple.AegeanSettingsFactory;import net.sf.jasperreports.chartthemes.simple.XmlChartTheme;import net.sf.jasperreports.chartthemes.spring.AegeanChartTheme;/*** @author denisputnam**/public class AssetReport { private static final Log log = LogFactory.getLog (AssetReport.class); /** * @param args */ public static void main(String[] args) throws JRException, IOException { // TODO Auto-generated method stub // String cwd = System.getProperty("user.dir");// System.out.println("cwd=" + cwd );// String nwd = "/Users/denisputnam/Perforce/dputnam_Deniss-MacBook-Pro_9025/depot/AssetJasperReports/src/main/webapp/resources/";// // System.setProperty("user.dir", nwd);// cwd = System.getProperty("user.dir");// System.out.println("cwd=" + cwd ); AegeanChartTheme aegeanChartTheme = new AegeanChartTheme(); XmlChartTheme.saveSettings( AegeanSettingsFactory.createChartThemeSettings(), new File("src/net/sf/jasperreports/chartthemes/simple/aegean.jrctx") ); // Compile jrxml file. JasperReport jasperReport = JasperCompileManager.compileReport( "/Users/denisputnam/Perforce/dputnam_Deniss-MacBook-Pro_9025/depot/AssetJasperReports/src/main/webapp/resources/ARKREPORT.jrxml");// JasperReport jasperReport = JasperCompileManager.compileReport(// "ARKREPORT.jrxml"); // Parameters for report Map<String, Object> parameters = new HashMap<String, Object>(); // DataSource // This is simple example, no database. // then using empty datasource. // JRDataSource dataSource = new JREmptyDataSource(); Connection myconnection = getConnection(); // Connection con = getConnection(); String jdbcString = "select * from asset"; PreparedStatement statement = null; try { statement = myconnection.prepareStatement(jdbcString.toString()); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ResultSet rs = null; try { rs = statement.executeQuery(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } JRDataSource dataSource = new JRResultSetDataSource(rs); // JRDataSource dataSource = new JREmptyDataSource(); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource); // Make sure the output directory exists. File outDir = new File("/Users/denisputnam/tmp"); outDir.mkdirs(); // Export to PDF. JasperExportManager.exportReportToPdfFile(jasperPrint, "/Users/denisputnam/tmp/StyledTextReport.pdf"); JasperExportManager.exportReportToHtmlFile(jasperPrint, "/Users/denisputnam/tmp/StyledTextReport.html"); System.out.println("Done!"); } static public Connection getConnection() { Connection connection = null; try { connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/assetcore", "assetcore", "password"); } catch (SQLException e) { e.printStackTrace(); } return connection; } /* * Here’s an example web.xml declaration for the datasource above: * * <resource-ref> <res-ref-name>jdbc/myds</res-ref-name> * <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> * </resource-ref> * * To look up your DataSource in your servlet/filter/etc.: * * import javax.naming.InitialContext; import javax.sql.DataSource; * * public class MyClass { * * public void myMethod() { * * InitialContext ic = new InitialContext(); DataSource myDS = * (DataSource)ic.lookup("java:comp/env/jdbc/myds"); * * ... } } */}[/code] Link to comment Share on other sites More sharing options...
hozawa Posted June 26, 2016 Share Posted June 26, 2016 Have you checked the following thread?http://community.jaspersoft.com/questions/824153/chart-theme-aegean-not-found-551 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