简体   繁体   中英

Compiling java classes using ant: cannot find symbol

I am totally new to ant and I want to start Selenium on a Linux RedHat machine. I face problems when I try to compile my java files with this build script. Why does it always say "cannot find symbol"?

build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Mink Admin GUI Tests" default="run" basedir=".">

    <!-- Property: Selenium Server -->
    <property name="selenium.port" value="4444"/>
    <property name="report.dir" value="${basedir}\reports"/>
    <property name="testng.dir" value="${basedir}\test-output"/>
    <property name="classes.dir" value="${basedir}\bin"/>
    <property name="src.dir" value="${basedir}\src"/>

    <!-- Inlcude all libs and java classes -->
    <path id="libs">
        <pathelement path="${basedir}/libs/junit/junit-4.11.jar"/>
        <pathelement path="${basedir}/libs/selenium-client/selenium-java-2.33.0.jar"/>
        <pathelement path="${basedir}/libs/selenium-server/selenium-server-standalone-2.33.0.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/apache-mime4j-0.6.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/bsh-1.3.0.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/cglib-nodep-2.1_3.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/commons-codec-1.6.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/commons-collections-3.2.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/commons-exec-1.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/commons-io-2.2.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/commons-jxpath-1.3.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/commons-lang3-3.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/commons-logging-1.1.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/cssparser-0.9.9.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/guava-14.0.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/hamcrest-core-1.3.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/htmlunit-2.12.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/htmlunit-core-js-2.12.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/httpclient-4.2.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/httpcore-4.2.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/httpmime-4.2.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/ini4j-0.5.2.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/jcommander-1.29.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/jetty-websocket-8.1.8.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/jna-3.4.0.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/jna-platform-3.4.0.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/json-20080701.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/junit-dep-4.11.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/nekohtml-1.9.17.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/netty-3.5.7.Final.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/operadriver-1.3.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/phantomjsdriver-1.0.3.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/protobuf-java-2.4.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/sac-1.3.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/serializer-2.7.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/testng-6.8.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/xalan-2.7.1.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/xercesImpl-2.10.0.jar"/>
        <pathelement path="${basedir}/libs/selenium-libs/xml-apis-1.4.01.jar"/>
    </path>

    <!-- Initial start target - run the test -->
    <target name="run" description="Initial target of this build script">
        <echo>Let's start!</echo>
        <sequential>
            <antcall target="init"/>
            <echo taskname="waitfor" message="(...waiting for selenium server launch...)"/>
            <waitfor maxwait="2" maxwaitunit="minute" checkevery="100">
                <http url="http://localhost:${selenium.port}/selenium-server/driver/?cmd=testComplete"/>
            </waitfor>
            <antcall target="tests"/>
            <antcall target="stop-server"/>
        </sequential>
    </target>

    <!-- Start server and compile Java files -->
    <target name="init">
        <echo>Setting up environment...</echo>
        <delete dir="logs"/>
        <mkdir dir="logs"/>
        <delete dir="${classes.dir}"/>
        <mkdir dir="${classes.dir}"/>
        <delete dir="${report.dir}"/>
        <mkdir dir="${report.dir}"/>
        <delete dir="${testng.dir}"/>
        <java jar="${basedir}/libs/selenium-server/selenium-server-standalone-2.33.0.jar" fork="true" spawn="true">
            <arg line="-timeout 30 -port ${selenium.port} -log logs/seleniumStart.log -browserSideLog"/>
        </java>
        <echo>Compiling java files...</echo>
        <javac debug="true" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="libs" encoding="UTF-8"></javac>
    </target>

    <!-- Run the testng.xml -->
    <target name="tests" description="Run TestNG">
        <echo>Let's run the Test Cases...</echo>
        <testng outputDir="${report.dir}" haltonfailure="false" classpathref="libs">
            <xmlfileset dir="." includes="tests.xml"/>
        </testng>
    </target>

    <!-- Stop the Selenium server -->
    <target name="stop-server">
        <echo>Stopping the Selenium Server...</echo>
        <get taskname="selenium-shutdown" src="http://localhost:${selenium.port}/selenium-server/driver/?cmd=shutDownSeleniumServer" dest="logs/seleniumStop.log" ignoreerrors="true"/>
    </target>
</project>

Output:

Buildfile: build.xml

run:
     [echo] Let's start!

init:
     [echo] Setting up environment...
   [delete] Deleting directory /opt/scp/pkg/logs
    [mkdir] Created dir: /opt/scp/pkg/logs
   [delete] Deleting directory /opt/scp/pkg/bin
    [mkdir] Created dir: /opt/scp/pkg/bin
   [delete] Deleting directory /opt/scp/pkg/reports
    [mkdir] Created dir: /opt/scp/pkg/reports
     [echo] Compiling java files...
    [javac] Compiling 1 source file to /opt/scp/pkg/bin
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:23: cannot find symbol
    [javac] symbol  : method verifyTrue(boolean)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyTrue(selenium.isTextPresent("Sign in to AdminGUI"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:69: cannot find symbol
    [javac] symbol  : method verifyEquals(java.lang.String,java.lang.String)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyEquals("e2e", selenium.getText("css=div.rf-cp-lbl-colps"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:70: cannot find symbol
    [javac] symbol  : method verifyEquals(java.lang.String,java.lang.String)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyEquals("Customers", selenium.getText("css=span.menu-item.menu-item-selected"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:71: cannot find symbol
    [javac] symbol  : method verifyTrue(boolean)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyTrue(selenium.isElementPresent("link=Mobile Users"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:72: cannot find symbol
    [javac] symbol  : method verifyTrue(boolean)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyTrue(selenium.isElementPresent("link=Certificates"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:73: cannot find symbol
    [javac] symbol  : method verifyTrue(boolean)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyTrue(selenium.isElementPresent("link=Provisioning Adapter"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:74: cannot find symbol
    [javac] symbol  : method verifyTrue(boolean)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyTrue(selenium.isElementPresent("link=Admin Users"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:75: cannot find symbol
    [javac] symbol  : method verifyEquals(java.lang.String,java.lang.String)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyEquals("Customer List", selenium.getText("id=breadcrumbs_body"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:90: cannot find symbol
    [javac] symbol  : method verifyTrue(boolean)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyTrue(selenium.isTextPresent("e2e"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:93: cannot find symbol
    [javac] symbol  : method verifyTrue(boolean)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyTrue(selenium.isTextPresent("Sign in to AdminGUI"));
    [javac]             ^
    [javac] /opt/scp/pkg/src/com/xxx/yyy/test/Login.java:94: cannot find symbol
    [javac] symbol  : method verifyTrue(boolean)
    [javac] location: class com.xxx.yyy.test.Login
    [javac]             verifyTrue(selenium.isTextPresent("Please authenticate based on your username"));
    [javac]             ^
    [javac] 11 errors

BUILD FAILED
/opt/scp/pkg/build.xml:58: The following error occurred while executing this line:
/opt/scp/pkg/build.xml:82: Compile failed; see the compiler error output for details.

Quoting from THIS page:

When a Java program is being compiled the compiler creates a list of all the identifiers in use. If it can't find what an identifier refers to (eg, there is no declaration statement for a variable) it cannot complete the compilation. This is what the cannot find symbol error message is saying, it doesn't have enough information to piece together what the Java code wants to execute.

Possible Causes:
- trying to use a variable without declaring it.
- misspelling a class or method name (remember, Java is case sensitive).
- the parameters used do not match a method's signature.
- the packaged class has not being referenced correctly using an import declaration.


In your case, the verifyTrue(..) and verifyEquals(..) methods, probably:
- have not been defined properly (method-name conflict), or
- are defined in a class which has not been import ed; relevant jar not included in the classpath ( Highly likely )

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