Sim,
this is more or less guessing:
looking at the source on
http://libloader.sourcearchive.com/documentation/0.3.4/ResourceManager_8java-source.html
(i hope this is not completely outdated), there either is no loader
registered, or no loader can handle the request. I hope you can remote
debug the JVM you start with Jython, and find out where the
ResourceManager behaves differently from the plain Java invocation.
I'd start with the registerDefaultLoaders() method:
00625 public void registerDefaultLoaders()
00626 {
00627 final Configuration config =
LibLoaderBoot.getInstance().getGlobalConfig();
00628 final Iterator it = config.findPropertyKeys(LOADER_PREFIX);
00629 while (it.hasNext())
00630 {
00631 final String key = (String) it.next();
00632 final String value = config.getConfigProperty(key);
00633 final Object o = ObjectUtilities.loadAndInstantiate(value,
ResourceManager.class, ResourceLoader.class);
00634 if (o != null)
00635 {
00636 final ResourceLoader loader = (ResourceLoader) o;
00637 //Log.debug("Registering loader for " + loader.getSchema());
00638 registerLoader(loader);
00639 }
00640 }
00641 }
HTH
Oti.
On Thu, Nov 27, 2008 at 10:52 AM, Sim Zacks <sim@...> wrote:
> I am trying to convert a script from java to jython and I am having a
> problem. I was hoping someone could help me. I actually wrote the script
> first in jython and then when it didn't work, wrote it in java so I
> could use the examples that were provided.
>
> The script now works in java but won't work in jython. Both scripts are
> pasted at the bottom of the email.
> Everything that is in the sys.path.append in the jython script is in the
> -classpath parameter when running the java script.
>
> I'm getting the error on the line that reads:
> res=manager.createDirectly(repfile,JFreeReport)
>
> In the java script, the parameter passed in is JFreeReport.class
> I have tried creating an instance of JFreeReport and passing it in it's
> class object
> x=JfreeReport()
> res=manager.createDirectly(repfile,x.class)
> with the same error.
>
> The error I'm getting is:
> Traceback (most recent call last):
> File "jython_jfree.jy", line 44, in ?
> res=manager.createDirectly(repfile,JFreeReport)
> org.jfree.resourceloader.ResourceKeyCreationException:
> org.jfree.resourceloader.ResourceKeyCreationException: Unable to create
> key: No loader was able to handle the given key data:
> file:/tmp/testporeport.xml
>
> One thing that I found odd is I'm getting the same error whether the
> file exists or not.
>
> Any thoughts?
> Sim
>
>
> JAVA
> _______________________________________________________________________
> import org.jfree.resourceloader.ResourceManager;
> import org.jfree.resourceloader.Resource;
> import org.jfree.report.JFreeReport;
> import org.jfree.report.JFreeReportBoot;
> import org.jfree.report.modules.output.pageable.pdf.PdfReportUtil;
> import org.jfree.report.modules.parser.base.ReportGenerator;
> import java.net.URL;
> import java.net.MalformedURLException;
> import org.jfree.resourceloader.ResourceLoadingException;
> import org.jfree.resourceloader.ResourceException;
> import org.jfree.resourceloader.ResourceCreationException;
>
> public class testreport{
> public static void main(String[] args){
> JFreeReportBoot.getInstance().start();
> System.out.println("Booted");
> String REPORT="file:///tmp/testporeport.xml";
> try {
> URL repfile= new URL(REPORT);
> ResourceManager manager= new ResourceManager();
> System.out.println("Manager");
> manager.registerDefaults();
> System.out.println("Defaults");
> Resource res=manager.createDirectly(repfile,JFreeReport.class);
> System.out.println("Created");
> JFreeReport rep= (JFreeReport) res.getResource();
> System.out.println("GotResource");
> PdfReportUtil.createPDF(rep,"/tmp/testporeport.pdf");
> System.out.println("PDF Created");
> }
> catch(ResourceException e)
> {}
> catch(MalformedURLException mue)
> {}
>
> }
> }
>
> _____________________________________________________________________________
> Jython
> _____________________________________________________________________________
> #!/usr/bin/jython
> import sys, traceback
> #Add all the possible used jars to the classpath
>
> sys.path.append("bsf-2.4.0.jar")
> sys.path.append("bsh-1.3.0.jar")
> sys.path.append("itext-1.5.2.jar")
> sys.path.append("jcommon-1.0.14.jar")
> sys.path.append("jcommon-serializer-0.2.0.jar")
> sys.path.append("libfonts-0.3.4.jar")
> sys.path.append("libformula-0.1.18.2.jar")
> sys.path.append("libloader-0.3.7.jar")
> sys.path.append("librepository-0.1.6.jar")
> sys.path.append("libxml-0.9.11.jar")
> sys.path.append("pentaho-reporting-engine-classic-0.8.9.10.jar")
> sys.path.append("pixie-0.8.10.jar")
> sys.path.append("poi-3.0.1-jdk122-final-20071014.jar")
> sys.path.append("/usr/share/jdbc-postgresql/lib/jdbc-postgresql.jar")
>
>
>
> #import the classes that are actually used.
> from org.jfree.resourceloader import ResourceManager
> from org.jfree.resourceloader import Resource
> from org.jfree.report import JFreeReport
> from org.jfree.report import JFreeReportBoot
> from org.jfree.report.modules.output.pageable.pdf import PdfReportUtil
> from org.jfree.report.modules.parser.base import ReportGenerator
> from java.net import URL
> from java.net import MalformedURLException
> from org.jfree.resourceloader import ResourceLoadingException
> from org.jfree.resourceloader import ResourceCreationException
>
> #Run the report
> JFreeReportBoot.getInstance().start()
> print "Booted"
> REPORT="file:///tmp/testporeport.xml"
> try:
> repfile=URL(REPORT)
> manager=ResourceManager()
> print "Manager"
> manager.registerDefaults()
> print "Defaults"
> res=manager.createDirectly(repfile,JFreeReport)
> print "Created"
> rep=res.getResource()
> print "Got Resource"
> PdfReportUtil.createPdf(rep,"/tmp/testporeport1.pdf")
> print "PDF Created"
> except:
> traceback.print_exc(file=sys.stdout)
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Jython-users mailing list
> Jython-users@...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
|