Search code examples
javanetbeansbatik

Error Directory Walker


I want to export a PDF file from SVG using Apache Batik. I encountered an error when I tried the following code:

private void buttonperformed(java.awt.event.actionEvent evt) {
    try {
        TranscoderInput transcoderInput = new TranscoderInput
                (new FileInputStream(new File("/Users/Decd/Desktop/input.svg")));

        TranscoderOutput transcoderOutput = new TranscoderOutput
                (new FileOutputStream(new File("/Users/Decd/Desktop/output.pdf")));

        transcoder.transcode(transcoderInput, transcoderOutput);

    } catch (FileNotFoundException | TranscoderException ex) {
        Logger.getLogger(ChartFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}

Meanwhile, this is the error message:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/io/DirectoryWalker
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)

Is there any way to fix my problem?


Solution

  • You are missing the dependency org.apache.commons:commons-io.

    To avoid facing many more similar dependency related problems in the future, you should try to use a dependency management tool like Ivy or a build tool capable of managing dependencies, like Maven or Gradle.