java - ANT build fails and gives classNotFoundExceeption in html report -


after doing many trial , errors on "how ant tag works ?", decided write own custom build xml file testcases written in java , integrated junit. unfortunately build script failing "classnotfoundexception". , can see log in generated html file see after running ant build script.

please see below

<project name="webservices integrated junit , generating report ant" default="test" basedir="." >  <description> rest services integration junit </description>      <!-- set global properties build -->          <property name="project_name" value="junit"/>         <property name="src" location="src"/>         <property name="build" location="bin"/>         <property name="dist" location="dist"/>         <property name="lib" location="${user.home}/my documents/mr/jars"/>         <property name="reports" location="reports"/>    <!-- names of various distributable files. note: generating distribution file "target" not used here-->     <!-- delete ${build} , ${dist} directory trees -->    <target name="clean" description="clean up">          <delete dir="${build}"/>          <delete dir="${dist}"/>          <delete dir="${reports}"/>    </target>     <!-- top level targets -->     <target name="compile" depends="init" description="compile source code">          <javac srcdir="${src}" destdir="${build}">                <classpath>                      <fileset dir="${lib}">                            <include name="**/*.jar"/>                      </fileset>                </classpath>          </javac>    </target>      <!-- run tests -->     <target name="run-tests" depends="compile" description="run test suite">          <junit printsummary="yes" haltonfailure="no" showoutput="yes">                <classpath>                      <pathelement path="${build}"/>                      <fileset dir="${lib}">                            <include name="**/*.jar"/>                      </fileset>                </classpath>                 <batchtest fork="yes" todir="${reports}/raw/">                      <formatter type="xml"/>                      <fileset dir="${src}/test/services" >                            <exclude name="myfile.java"/>                            <include name="**/*.java"/>  // <------ imp***: here saying include .java files based @ "${src}/test/services".                      </fileset>                </batchtest>          </junit>    </target>     <!-- generate report on tests -->      <target name="test" depends="run-tests">          <junitreport todir="${reports}">                <fileset dir="${reports}/raw/">                            <include name="test-*.xml"/>                </fileset>                 <report format="frames" todir="${reports}/html/"/>          </junitreport>    </target>      <target name="init" depends="clean" description="initialize build envrionment">                <!--create time stamp -->                <tstamp/>                <!-- create directory structure -->                <mkdir dir="${build}"/>       //<----dir class files                <mkdir dir="${lib}"/>         //<----dir libraries                <mkdir dir="${dist}/lib"/>    //<----not used                <mkdir dir="${reports}"/>                <mkdir dir="${reports}/raw/"/>                <mkdir dir="${reports}/html/"/>     //<---- have output reports     </target>      <target name="all" depends="clean,test">    </target> 

and guessed ant build pick source files (.java) , class files based in build folder , started running them, see "classnotfoundexception" in html report. please see below log :

class : "getlieninfo"

>   java.lang.classnotfoundexception: getlieninfo @ java.net.urlclassloader$1.run(urlclassloader.java:366) @ java.net.urlclassloader$1.run(urlclassloader.java:355) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(urlclassloader.java:354) @ java.lang.classloader.loadclass(classloader.java:423) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:308) @ java.lang.classloader.loadclass(classloader.java:356) @ java.lang.class.forname0(native method) @ java.lang.class.forname(class.java:186) 

after while changed .java .class in "include" tag of target called "run-tests" . reason doing is, thought ant not able ".java" files in source folder (src/test/services) hence changed ".class" , modified dir attribute value in "fileset" tag "build" may ".class" in build folder have compiled files stored. none of trial , error succeeded , ended same "classnotfoundexception".

i not sure went wrong , can me, please?

ok guys, ever little got you. found problem.

i had change include tag attribute name "name=/test/services/**/*.java"/>" , modify dir attribute in fileset tag "${src}" ; see below :

<batchtest fork="yes" todir="${reports}/raw/">        <formatter type="xml"/>          <fileset dir="${src}" >              <exclude name="myfile.java"/>                 <include name="/test/services/**/*.java"/>  //<----this had modify. 

note: under src directory have test/services folder has source ".java" files in it.

        </fileset> </batchtest> 

it solved problem, don't understand why ant build not able identify source files when gave dir attribute dir="${src}/test/services" in fileset tag , kept name attribute in include tag name="**/*.java" . understanding fileset tag should build path for given dir path , once path build include tag include or mentioned source files i.e. ".java" .


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -