简体   繁体   中英

Javac Ant task can't find a class even though it is contained in the classpath

My javac Ant task produces errors like those shown below:

[javac] C:\dp\dev\trunk\MyProduct\MyUnitTest.java:109: error: cannot find symbol
[javac]     private MyClass createFactoryMock() throws Exception {
[javac]             ^
[javac]   symbol:   class MyClass
[javac]   location: class MyUnitTest

I ran the task in a verbose mode ( ant -verbose test-compile ) and found MyClass in the classpath output of the task, from which I conclude that MyClass is present in the classpath.

[javac] Compiling 9 source files to C:\dp\dev\trunk\MyProduct\temp\test-build

[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-d'
[javac] 'C:\dp\dev\trunk\MyProduct\temp\test-build'
[javac] '-classpath'
[javac] '[...]C:\dp\dev\trunk\MyProduct\temp\build\MyProduct\MyClass.class[...]

What else (apart from classpath issues) can be the cause of the error?

I fixed the problem by changing

    <javac srcdir="${test}" destdir="temp/test-build" debug="${debug}" encoding="UTF-8">
        <classpath>
            [...]
            <fileset dir="${build}"/>
        </classpath>
    </javac>

to

    <javac srcdir="${test}" destdir="temp/test-build" debug="${debug}" encoding="UTF-8">
        <classpath>
            [...]
            <pathelement location="${build}"/>
        </classpath>
    </javac>

Make it point to your exact jar files directory where the jars are present:

<path id="classpath">
    <fileset dir="${main.jar}" includes="**/*.jar"/>
    <!-- <pathelement location="${src.dir}" />-->
</path>

----in my case jar files present in ----

<property name="main.jar" value="jar"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM