1

尽管所需的 jar 在类路径中,但javac我的目标中的任务失败了。compile谁能帮我弄清楚为什么会这样?

下面的错误是由于IOUtils.lineIterator()无法识别引起的。但是,commons-io-1.3.1.jar位于构建路径(在 中${app.lib.dir})。因此,构建失败很奇怪。

<target name="compile">
    <mkdir dir="${classes.dir}" />
    <javac destdir="${classes.dir}" debug="true" classpathref="dependency.path"
        excludes="/../security/**" >
        <src path="${java.src.dir}" />
    </javac>
</target>

<path id="dependency.path">
    <fileset dir="${spring.lib.dir}" includes="*.jar" />
    <fileset dir="${spring.depends.dir}" includes="**/*.jar" />
    <fileset dir="${app.lib.dir}" includes="*.jar" />
    <fileset dir="${tomcat.dir}/.." includes="**/*.jar" />
</path>

执行

ant -f build-dev.xml compile

Buildfile: C:\..\build-dev.xml compile:
    [mkdir] Created dir: C:\..\classes
    [javac] Compiling 348 source files to C:\..\classes
    [javac] C:\..\UploadUtil.java:132: cannot find symbol
    [javac] symbol  : method lineIterator(java.io.InputStream,java.lang.String)
    [javac] location: class org.apache.commons.io.IOUtils
    [javac]             Iterator<String> it = IOUtils.lineIterator(is, charSet);
    [javac]                                          ^
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 1 error

BUILD FAILED
C:\..\build-dev.xml:54: Compile failed; see the compiler error output for details.

Total time: 11 seconds

尝试的方法

  1. 令人惊讶的是, Eclipse正在毫无问题地构建项目。我在项目构建路径上有相同的 jar 集。我也有从编译中排除的相同源目录。
  2. 尝试在源文件夹上使用javac可执行文件,但不确定如何在源代码目录结构上使用 javac。
  3. 我确定我拥有的 jar 版本有这个类IOUtils,因为 Eclipse 在 jar 的内容中显示了它。
4

1 回答 1

4

The most likely explanation is that the jar containing the class is not on the classpath.

I double-checked Maven Central, just in case there was a jar called "commons-io-1.3.1" that does not contain this class, but sadly no:

So I'd suggest is that you add the following diagnostic target into your build so that you can confirm that the jar is in fact on the classpath:

<target name="diagnostics">
    <pathconvert property="classpathProp" refid="dependency.path"/>

    <echo>Classpath is ${classpathProp}</echo>
</target>
于 2013-01-18T21:29:47.787 回答