Dima Alexei Dima Alexei - 1 year ago 68
Java Question

I try to create a build in ant were it create a html report which will start my .class file

Hello I try to create a build in ant were it create a html report which will start my .class file from eclips

"


<property name="src" value="D:/Automation/eclipse/MyWork/OpenCart/src" />
<property name="lib" value="D:/Automation/eclipse/MyWork/OpenCart/lib/" />
<property name="bin" value="D:/Automation/eclipse/MyWork/build" />
<property name="report" value="d:/Automation/report" />
<path id="test.classpath">


<pathelement location="${bin}"/>
<fileset dir="${lib}">
<include name="${lib}/junit.jar" />
</fileset>
</path>

<target name="init">
<delete dir="${bin}" />
<mkdir dir="${bin}" />
</target>
<target name="compile" depends="init">
<javac source="1.7" srcdir="${src}" fork="true" destdir="${bin}" includeantruntime="false" >
<classpath>
<pathelement path="${bin}">
</pathelement>
<fileset dir="${lib}">
<include name="${src}/TestCases/OpenCart.class" />
</fileset>
</classpath>
</javac>
</target>

<target name="exec" depends="compile">
<delete dir="${report}" />
<mkdir dir="${report}" />
<mkdir dir="${report}/xml" />
<junit printsummary="yes" haltonfailure="no">
<classpath>
<pathelement location="${bin}" />
<fileset dir="${lib}">
<include name="${src}/TestCases/OpenCart.class" />
</fileset>
</classpath>

<test name="com.selftechy.seltests.SeleniumTest" haltonfailure="no" todir="${report}/xml" outfile="TEST-result">
<formatter type="xml" />
</test>
</junit>
<junitreport todir="${report}">
<fileset dir="${report}/xml">
<include name="TEST*.xml" />
</fileset>
<report format="frames" todir="${report}/html" />
</junitreport>
</target>


"

I get the error :
"


Buildfile: D:\Automation\eclipse\MyWork\OpenCart\Build.xml init:

[delete] Deleting directory D:\Automation\eclipse\MyWork\build
[mkdir] Created dir: D:\Automation\eclipse\MyWork\build compile:
[javac] Compiling 1 source file to D:\Automation\eclipse\MyWork\build
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:3: error: package com.thoughtworks.selenium does not exist
[javac] import com.thoughtworks.selenium.;
[javac] ^
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:5: error: package org.junit does not exist
[javac] import org.junit.After;
[javac] ^
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:6: error: package org.junit does not exist
[javac] import org.junit.Before;
[javac] ^
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:7: error: package org.junit does not exist
[javac] import org.junit.Rule;
[javac] ^
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:8: error: package org.junit does not exist
[javac] import org.junit.Test;
[javac] ^
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:9: error: package org.junit.rules does not exist
[javac] import org.junit.rules.ErrorCollector;
[javac] ^
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:11: error:
package org.junit does not exist
[javac] import static org.junit.Assert.
;
[javac] ^
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:14: error:
cannot find symbol
[javac] private Selenium selenium;
[javac] ^
[javac] symbol: class Selenium
[javac] location: class OpenCart
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:17: error:
cannot find symbol
[javac] public ErrorCollector errorCollector = new ErrorCollector();
[javac] ^
[javac] symbol: class ErrorCollector
[javac] location: class OpenCart
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:16: error:
cannot find symbol
[javac] @Rule
[javac] ^
[javac] symbol: class Rule
[javac] location: class OpenCart
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:19: error:
cannot find symbol
[javac] @Before
[javac] ^
[javac] symbol: class Before
[javac] location: class OpenCart
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:25: error:
cannot find symbol
[javac] @Test
[javac] ^
[javac] symbol: class Test
[javac] location: class OpenCart
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:128: error:
cannot find symbol
[javac] @After
[javac] ^
[javac] symbol: class After
[javac] location: class OpenCart
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:17: error:
cannot find symbol
[javac] public ErrorCollector errorCollector = new ErrorCollector();
[javac] ^
[javac] symbol: class ErrorCollector
[javac] location: class OpenCart
[javac] D:\Automation\eclipse\MyWork\OpenCart\src\OpenCart.java:21: error:
cannot find symbol
[javac] selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://IP/");
[javac] ^
[javac] symbol: class DefaultSelenium
[javac] location: class OpenCart
[javac] 15 errors

BUILD FAILED D:\Automation\eclipse\MyWork\OpenCart\Build.xml:23:
Compile failed; see the compiler error output for details.

Total time: 1 second


the ${lib} contains all the libs I used to create this class and running only the class work 100% but when I try to run the build as a ant build in eclips it give me this erros

I have set the %JAVA_HOME% to jdk and in cmd I run javac and it find it
the junit.jar is in ${lib} and in %ANT_HOME%/lib and in %JAVA_HOME%/lib

please help !!!

Answer Source

Try the following build.xml. Please keep it in mind the following change you need to do manually in this file

  1. Project name in very first line
  2. lib.dir address should be the one where all of your jars are kept physically. I suggest create a dir, put all the jars in this and give the address over here.
  3. the report directory I have changed and now it is under the project directory, parallel to src. If you need you can change it.

Please note that I have changed my build.xml having many other features to the one you are comfortable. I have updated it very carefully, though very few changes may left by mistake that I suppose you can do. still if you found any problem, I would love to help you as far as I can.

    <project name="ProjectName" basedir=".">
    <property name="home.dir" value="${basedir}"/>
    <property name="build.dir" value="${home.dir}/build"/>
    <property name="src.dir" value="${home.dir}/src"/>
    <property name="report.dir" value="${home.dir}/report" />
    <property name="lib.dir" value="H:/Selenium/jar_collection"/>
    <!-- setClassPath -->
    <target name="setClassPath">
        <path id="classpath_jars">
            <pathelement path="${basedir}/" />
            <fileset dir="${lib.dir}" includes="*.jar" />
        </path>
        <pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" />
    </target>
    <!-- build -->
    <target name="build">
        <mkdir dir="${build.dir}"/>
        <tstamp>
            <format property="timestamp" pattern="dd-MM-yyyy_(HH-mm-ss)"/>
        </tstamp>
        <property name="build.log.dir" location="${basedir}/buildlogs"/>
        <mkdir dir="${build.log.dir}"/>
        <property name="build.log.filename" value="build_${timestamp}.log"/>
        <record name="${build.log.dir}/${build.log.filename}" loglevel="verbose" append="false"/>
        <echo message="build logged to ${build.log.filename}"/>
    </target>
    <!-- Clean -->
    <target name="clean">
        <echo message="deleting existing build directory"/>
        <delete dir="${build.dir}"/>
    </target>
    <!-- Compile -->
    <target name="compile" depends="clean,build,setClassPath">
        <echo message="classpath:${test.classpath}"/>
        <echo message="compiling.........."/>
        <javac destdir="${build.dir}" srcdir="${src.dir}" classpath="${test.classpath}"/>
    </target>
    <!-- Execute -->    
    <target name="exec" depends="compile">
        <delete dir="${report.dir}" />
        <mkdir dir="${report.dir}" />
            <mkdir dir="${report.dir}/xml" />
        <junit printsummary="yes" haltonfailure="no">
            <classpath>
                <pathelement location="${build.dir}" />
                <fileset dir="${lib.dir}">
                    <include name="${src.dir}/TestCases/OpenCart.class" />
                </fileset>
            </classpath>
            <test name="com.selftechy.seltests.SeleniumTest" haltonfailure="no" todir="${report.dir}/xml" outfile="TEST-result">
                <formatter type="xml" />
            </test>
        </junit>
        <junitreport todir="${report.dir}">
            <fileset dir="${report.dir}/xml">
                <include name="TEST*.xml" />
            </fileset>
            <report format="frames" todir="${report.dir}/html" />
        </junitreport>
    </target>
    </project>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download