ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.28k stars 121 forks source link

Trying to use FOP with .Net 8, but FopFactory.newInstance() fails with "Could not load source 'ClassLoader.java': Incorrect format of 'source' message.." #605

Open ZoBoRf opened 1 month ago

ZoBoRf commented 1 month ago

I am trying to run FOP with using the following test program:

using java.io;

using javax.xml.transform;
using javax.xml.transform.sax;
using javax.xml.transform.stream;

using org.apache.fop.apps;

public class Program
{
    public static void Main(string[] args)
    {
        var outputStream = new java.io.FileOutputStream("Data/test1.pdf");
        var uri = new java.io.File(".").toURI();
        var fopFactory = FopFactory.newInstance(uri);
        var userAgent = fopFactory.newFOUserAgent();
        var fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, outputStream);
        var transformerFactory = TransformerFactory.newInstance();
        var transformer = transformerFactory.newTransformer(new StreamSource(new java.io.File("Data/test1.fo")));
        transformer.setParameter("version", "1.0");
        var xmlSource = new StreamSource(new java.io.File("Data/test1.xml"));
        var result = new SAXResult(fop.getDefaultHandler());
        transformer.transform(xmlSource, result);
    }

The project file is:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="IKVM" Version="8.10.2" />
    <PackageReference Include="IKVM.Maven.Sdk" Version="1.8.2" />
    <MavenReference Include="org.apache.xmlgraphics:fop-core" Version="2.8" />
  </ItemGroup>
</Project>

Stepping through the program fails on the line

        var fopFactory = FopFactory.newInstance(uri);

and the following happens:

Some exceptions are thrown and a new file ClassLoader.java is opened in a new VS Code tab with the following contents :

grafik

But when I change the project file to:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FOP.NetCore" Version="3.0.0" />
  </ItemGroup>

</Project>

all works as expected. But, to be honest, I would rather do it without this package.

wasabii commented 1 month ago

The exceptions I see are ClassNotFound and/or Illegal argument. You'll need to provide the stack traces for those.