javaitext7xfa

Why am I getting a NoClassDefFoundError in the pdfXFA example?


Trying the example found from here: https://itextpdf.com/en/products/itext-7/pdfxfa

public static void main() {
        XFAFlattenerProperties flattenerProperties = new XFAFlattenerProperties()
                .setPdfVersion(XFAFlattenerProperties.PDF_1_7)
                .createXmpMetaData()
                .setTagged()
                .setMetaData(
                        new MetaData()
                            .setAuthor("iText Samples")
                            .setLanguage("EN")
                            .setSubject("Showing off our flattening skills")
                            .setTitle("Flattened XFA"));

        XFAFlattener xfaf = new XFAFlattener()
                .setFlattenerProperties(flattenerProperties);


        xfaf.flatten(new FileInputStream("xfaform.pdf"), new FileOutputStream("flat.pdf"));
}

and getting java.lang.NoClassDefFoundError: org.mozilla.javascript.ScriptableObject when trying to do XFAFlattener xfaf = new XFAFlattener();

Not using Maven or POM. I have the following JARs in classpath:

Am I missing something?


Solution

  • You need org.mozilla:rhino:1.7R4 dependency: https://mvnrepository.com/artifact/org.mozilla/rhino/1.7R4

    But as @Harry Coder mentioned, you should use Maven or Gradle or any other Maven-compatible build system that will download all the dependencies including transitive ones automatically for you