简体   繁体   中英

Eclipse don't recognize test folder as source folder when importing ant build file

I have an ant build file for a java project the project tree looks like this :
DataBaseFidling.
|-->src (contains production code source)
|-->tests (contains tests code source)
|-->bin (contains .class)
|-->reports(contains junit xml reports)
|-->build.xml

Whenever I import this project with eclipse using "Java Project From Existing Ant Build File", eclipse does not reconize the tests folder as a source folder.
What to do to fix this?
Here is the ant build file :
The DatabaseFidling Project.

     <property name="src.dir" location="./src/" />     
     <property name="tests.dir" location="./tests/" />     
     <property name="bin.dir" location="./bin/" />     
     <property name="lib.dir" location="/home/chedy/workspace/lib"/>

     <target name="clean">
         <delete verbose="true">
             <fileset dir="${bin.dir}"/>
         </delete>
     </target>

     <target name="compile">
        <javac srcdir="${src.dir}" destdir="${bin.dir}">
        </javac>
        <javac srcdir="${tests.dir}" destdir="${bin.dir}">
             <classpath>
                <pathelement location="${lib.dir}/junit4.jar"/>
                <pathelement location="${lib.dir}/mockito-all-1.9.5.jar"/> 
                <pathelement location="${lib.dir}/SQLScriptRunner.jar"/> 
            </classpath>
        </javac>
     </target>

     <target name="test" depends="compile">
        <junit printsummary="yes" fork="true" >
            <formatter type="xml"/> 
            <classpath>
                <pathelement path="${bin.dir}"/> 
                <pathelement location="${lib.dir}/junit4.jar"/>
                <pathelement location="${lib.dir}/mockito-all-1.9.5.jar"/> 
                <pathelement location="${lib.dir}/SQLScriptRunner.jar"/>
                <pathelement location="${lib.dir}/mysql-connector-java-5.1.23-bin.jar" />
            </classpath>
            <batchtest todir="./report">
                 <fileset dir="${bin.dir}">
                         <include name="**/**Test*.*"/> 
                 </fileset>  
            </batchtest>
        </junit>
     </target>

     <target name="run" depends="compile">
        <java classname="com.esprit.is.Main" fork="true">
            <classpath>
                 <pathelement path="${bin.dir}"/>
                 <pathelement location="${lib.dir}/mysql-connector-java-5.1.23-bin.jar" />
            </classpath>
        </java>
     </target>

</project>

编译目标必须包含一个javac任务,该任务同时编译src和test文件夹。

You can manually add the test folder as a source folder. Right click the project, Build Path -> Configure Build Path -> Java Build Path. In the Source tab, click Link Source then browse to your folder.

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