Jump to content

How Can I resolved this


remcastle

Recommended Posts

 Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/io/Resource

        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:161)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:119)
        at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(ClassUtils.java:57)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.instantiateRegistry(DefaultExtensionsRegistry.java:202)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:179)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:139)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getRegistries(DefaultExtensionsRegistry.java:125)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:102)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.findComponentBundles(ComponentsEnvironment.java:94)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.getCachedComponentBundles(ComponentsEnvironment.java:82)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.getComponentBundles(ComponentsEnvironment.java:70)
        at net.sf.jasperreports.engine.xml.JRReportSaxParserFactory.getSchemaLocations(JRReportSaxParserFactory.java:162)
        at net.sf.jasperreports.engine.xml.JRReportSaxParserFactory.configureParser(JRReportSaxParserFactory.java:143)
        at net.sf.jasperreports.engine.xml.JRReportSaxParserFactory.createParser(JRReportSaxParserFactory.java:108)
        at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParser(JRXmlDigesterFactory.java:1316)
        at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1291)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:203)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:168)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:152)
        at theschool.iReport.newReport.main(newReport.java:30)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.io.Resource
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        ... 22 more
Code:
public class newReport {    /**     * @param args the command line arguments     */    public static void main(String[] args) {        String path = "f:/projects/theschool/src/theSchool/iReport/newReport.jrxml";        try {            System.out.println("Loading...");            JasperDesign jasDsgn = JRXmlLoader.load(path);            JasperReport jasRpt = JasperCompileManager.compileReport(jasDsgn);            JasperPrint jasPrnt = JasperFillManager.fillReport(jasRpt, new HashMap());            JasperViewer.viewReport(jasPrnt);            System.out.println("Done");        } catch (Exception ex) {            System.out.println("Cannot Load");            System.err.println("Exception: " + ex.getMessage());        }    }}
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I don't know if this is the problem or not, but the main difference I see between your Java code and the small test program that I've been able to get working is your call to JasperFillManager.fillReport.  You pass a JasperReport and a HashMap for any passed parameters, but in my code, I also pass a third argument, which is a database Connection.  So in my code, I import the same files you do, plus

import java.sql.Connection;  import java.sql.DriverManager;

I have a method called connectToDatabase defined as follows:

  public static Connection connectToDatabase(String databaseName, String userName, String password) {
    Connection connection = null;
    try {
      Class.forName("com.ibm.db2.jcc.DB2Driver");
      connection = DriverManager.getConnection(databaseName,userName,password);
    } catch(Exception e) {
      String text = "Could not connect to the database: " + e.getMessage() + " " + e.getLocalizedMessage();
      System.out.println(text);
    }
    return connection;
  }
 

and then before I even call JRXmlLoader.load, I do this:

      Connection connection = connectToDatabase(databaseName, userName, password);
      System.out.println("Done with connectToDatabase!");

Later, my call to JasperFillManager.fillReport looks like this:

      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, connection);
      System.out.println("Done with fillReport!");

After that, our code diverges, because you view the report, while I have mine create a PDF file, but your viewReport call looks correct to me.  Hope that helps!

Carl

P.S.: Obviously my code to connect might be different from what you need--I'm connecting to a DB2 database.
 



Post Edited by cbarlow3 at 12/27/2010 16:06
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...