Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Oct 22, 2024 · 1 comment

Comments

@ZoBoRf
Copy link

ZoBoRf commented Oct 22, 2024

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
Copy link
Contributor

wasabii commented Oct 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants