我用ikvm从fop-1.0生成了一个fop.dll:
ikvmc -target:library -reference:IKVM.OpenJDK.Core.dll -recurse:{myPathToJars}\*.jar -version:1.0 -out:{myPathToJars}\fop.dll
如果我在Windows应用程序中使用我的fop.dll,一切都很完美.
如果我在类库中使用它,我会收到以下错误:
"Provider com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl not found" at javax.xml.transform.TransformerFactory.newInstance()
代码行是:
TransformerFactory factory = TransformerFactory.newInstance();这是方法的代码:
public static void xmlToPDF(String xmlPath, String xslPath, SortedList arguments, String destPdfPath)
{
java.io.File xmlfile = new java.io.File(xmlPath);
java.io.File pdffile = new java.io.File(destPdfPath);
try
{
// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
// Setup output
OutputStream outputStream = new java.io.FileOutputStream(pdffile);
outputStream = new java.io.BufferedOutputStream(outputStream);
try
{
// Construct fop with desired output format
Fop fop = fopFactory.newFop("application/pdf" /*MimeConstants.MIME_PDF*/, foUserAgent, outputStream);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
java.io.File xsltfile = new java.io.File(xslPath);
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile.getAbsoluteFile()));
// Set the value of a in the stylesheet
if (arguments != null)
{
IList keys = arguments.GetKeyList();
foreach (var key in keys)
{
Object value = arguments[key];
transformer.setParameter(key.ToString(), value);
}
}
// Setup input for XSLT transformation
Source src = new StreamSource(xmlfile);
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
}
catch (Exception e1)
{
System.Console.WriteLine(e1.Message);
}
finally
{
outputStream.close();
}
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
我使用ikvm-0.46.0.1来制作我的fop.dll(基于fop 1.0).我加入了以下罐子:
avalon-framework-4.2.0.jar batik-all-1.7.jar commons-io-1.3.1.jar commons-logging-1.0.4.jar fop.jar serializer-2.7.0.jar xalan-2.7.0.jar xercesImpl-2.7.1.jar xml-apis-1.3.04.jar xml-apis-ext-1.3.04.jar xmlgraphics-commons-1.4.jar
知道为什么会出现这个错误吗?为什么Windows应用程序和类库之间的行为有所不同?
加法10/19/11:
我设法开展以下工作:
但对于我的情况,这不是解决方案,因为在我的目标项目中,我有以下结构:
不幸的是,这种结构会导致错误.
你可以缩短成对(ACmdLinePrg,MyFopWrapper):已经不行了!但是(MyMainPrg,MyFopWrapper)确实......
以下是我如何得到该错误以及如何解决:
我的解决方案是这样的:
ClientApp (references)--> ClassLibrary1
Run Code Online (Sandbox Code Playgroud)
我的 ClassLibrary1 公共函数正在使用,但未公开任何 IKVM 相关对象,因此调用方 (ClientApp) 不必添加 IKVM 引用。在编译时一切都很好。
但是在运行时,情况就不同了。我遇到了同样的异常,并意识到 ClientApp 还需要引用包含“ com.sun.org.apache.xalan.@internal.xsltc.trax ”命名空间的正确 IKVM dll ( IKVM.OpenJDK.XML.Transform.dll ) 。
| 归档时间: |
|
| 查看次数: |
4183 次 |
| 最近记录: |