javaeclipsebuildjareclipse-oxygen

eclipse Ant Build package does not exist


I'm trying to generate a .jar in eclipse (Run as Ant Build) and I get errors like this one about the Apache's jars I added:

[javac] *path...*: error: package org.apache.commons.io does not exist
[javac] import org.apache.commons.io.FilenameUtils;

The jars were add from BuildPath -> Add External Jar.

Did I miss any step?


Solution

  • You need to configure compilation path in your build.xml It could be done like this

    <path id="main.classpath">
      <fileset dir="<directory with your jar dependencies>">
         <include name="*.jar"/>
      </fileset>
    

    And then add link to that path into your javac task

    <javac destdir="<directory where to store class files>" srcdir="<directory with java files>" debug="on" compiler="modern">
         <classpath refid="main.classpath"/> <!-- this is where you tell javac which path to use -->
    </javac>