gpt4 book ai didi

java - 如何告诉 Java 库在 Jython 中使用哪些属性

转载 作者:行者123 更新时间:2023-11-29 09:07:33 26 4
gpt4 key购买 nike

我在使用 Jython 运行 xmldatasource 示例项目时遇到问题。

这是我的代码:

#!/usr/bin/jython

"""
- cd buildEnv/xmldatasource; ant javac
- cd buildEnv/xmldatasource/build/classes; jar -cf xmldatasource.jar XmlDataSourceApp.class
- copy buildEnv/xmldatasource/build/classes/xmldatasource.jar to deploy/lib/xmldatasource.jar
"""

import os
import sys

cwd = os.path.realpath(".")

sys.path.extend([cwd + '/lib/xmldatasource.jar'])
sys.path.extend([cwd + '/lib/jasperreports-5.0.0.jar'])
sys.path.extend([cwd + '/lib/ant-1.7.1.jar'])
sys.path.extend([cwd + '/lib/antlr-2.7.5.jar'])
sys.path.extend([cwd + '/lib/barbecue-1.5-beta1.jar'])
sys.path.extend([cwd + '/lib/barcode4j-2.1.jar'])
sys.path.extend([cwd + '/lib/batik-anim.jar'])
sys.path.extend([cwd + '/lib/batik-awt-util.jar'])
sys.path.extend([cwd + '/lib/batik-bridge.jar'])
sys.path.extend([cwd + '/lib/batik-css.jar'])
sys.path.extend([cwd + '/lib/batik-dom.jar'])
sys.path.extend([cwd + '/lib/batik-ext.jar'])
sys.path.extend([cwd + '/lib/batik-gvt.jar'])
sys.path.extend([cwd + '/lib/batik-parser.jar'])
sys.path.extend([cwd + '/lib/batik-script.jar'])
sys.path.extend([cwd + '/lib/batik-svg-dom.jar'])
sys.path.extend([cwd + '/lib/batik-svggen.jar'])
sys.path.extend([cwd + '/lib/batik-util.jar'])
sys.path.extend([cwd + '/lib/batik-xml.jar'])
sys.path.extend([cwd + '/lib/bcel-5.2.jar'])
sys.path.extend([cwd + '/lib/bsh-2.0b4.jar'])
sys.path.extend([cwd + '/lib/castor-1.2.jar'])
sys.path.extend([cwd + '/lib/commons-beanutils-1.8.0.jar'])
sys.path.extend([cwd + '/lib/commons-collections-2.1.1.jar'])
sys.path.extend([cwd + '/lib/commons-digester-2.1.jar'])
sys.path.extend([cwd + '/lib/commons-javaflow-20060411.jar'])
sys.path.extend([cwd + '/lib/commons-logging-1.1.1.jar'])
sys.path.extend([cwd + '/lib/dom4j-1.6.1.jar'])
sys.path.extend([cwd + '/lib/groovy-all-2.0.1.jar'])
sys.path.extend([cwd + '/lib/hibernate3.jar'])
sys.path.extend([cwd + '/lib/hsqldb-1.8.0-10.jar'])
sys.path.extend([cwd + '/lib/iText-2.1.7.js1.jar'])
sys.path.extend([cwd + '/lib/jackson-annotations-2.0.5.jar'])
sys.path.extend([cwd + '/lib/jackson-core-2.0.5.jar'])
sys.path.extend([cwd + '/lib/jackson-databind-2.0.5.jar'])
sys.path.extend([cwd + '/lib/jaxen-1.1.1.jar'])
sys.path.extend([cwd + '/lib/jcommon-1.0.15.jar'])
sys.path.extend([cwd + '/lib/jdt-compiler-3.1.1.jar'])
sys.path.extend([cwd + '/lib/jfreechart-1.0.12.jar'])
sys.path.extend([cwd + '/lib/jpa.jar'])
sys.path.extend([cwd + '/lib/jxl-2.6.10.jar'])
sys.path.extend([cwd + '/lib/log4j-1.2.15.jar'])
sys.path.extend([cwd + '/lib/mondrian-3.1.1.12687.jar'])
sys.path.extend([cwd + '/lib/png-encoder-1.5.jar'])
sys.path.extend([cwd + '/lib/poi-3.7-20101029.jar'])
sys.path.extend([cwd + '/lib/poi-ooxml-3.7-20101029.jar'])
sys.path.extend([cwd + '/lib/poi-ooxml-schemas-3.7-20101029.jar'])
sys.path.extend([cwd + '/lib/rhino-1.7R3.jar'])
sys.path.extend([cwd + '/lib/saaj-api-1.3.jar'])
sys.path.extend([cwd + '/lib/serializer.jar'])
sys.path.extend([cwd + '/lib/servlet-api-2.4.jar'])
sys.path.extend([cwd + '/lib/spring-beans-2.5.5.jar'])
sys.path.extend([cwd + '/lib/spring-core-2.5.5.jar'])
sys.path.extend([cwd + '/lib/velocity-1.7-dep.jar'])
sys.path.extend([cwd + '/lib/xalan-2.7.1.jar'])
sys.path.extend([cwd + '/lib/xbean.jar'])
sys.path.extend([cwd + '/lib/xercesImpl-2.9.0.jar'])
sys.path.extend([cwd + '/lib/xml-apis-ext.jar'])
sys.path.extend([cwd + '/lib/xml-apis.jar'])

import XmlDataSourceApp

from java import util
import java.io as javaio
properties = util.Properties()
propertiesfis =javaio.FileInputStream("jasperreports.properties")
properties.load(propertiesfis)

javaObj = XmlDataSourceApp()

javaObj.fill()

如您所见,所有依赖项都应该加载。当我尝试调用 fill() 方法时,我收到以下错误:

og4j:WARN No appenders could be found for logger (net.sf.jasperreports.extensions.ExtensionsEnvironment).
log4j:WARN Please initialize the log4j system properly.
Traceback (innermost last):
File "java.py", line 84, in ?
at net.sf.jasperreports.engine.util.JRQueryExecuterUtils.getExecuterFactory(JRQueryExecuterUtils.java:114)
at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1082)
at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:667)
at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1258)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:877)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:126)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:464)
at net.sf.jasperreports.engine.JasperFillManager.fillToFile(JasperFillManager.java:249)
at net.sf.jasperreports.engine.JasperFillManager.fillToFile(JasperFillManager.java:155)
at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:678)
at XmlDataSourceApp.fill(XmlDataSourceApp.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)

net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRRuntimeException: No query executer factory registered for the 'xPath' language.

我只使用 jython java.py 运行这段代码。

我认为代码不起作用,但我不知道如何正确设置属性。根据示例项目,属性必须设置如下:

net.sf.jasperreports.xpath.executer.factory=net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory

但是如果我使用 Jython 呢?

最佳答案

我使用 PY4J 而不是 Jython 解决了 java 属性的问题。

关于java - 如何告诉 Java 库在 Jython 中使用哪些属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14058146/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com