我正在使用ANT和IVY来解决依赖关系并构建项目。我必须编写一个selenium测试用例,所以我在IVY文件中包含了selenium依赖项,如下所示:
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.48.2"/>
IVY能够下载依赖项,但是当我使用ANT编译项目时,它失败并出现以下错误:
cannot find symbol
[javac] symbol : class WebDriver
[javac] location: class com.barclays.test.selenium.TestSelenium
[javac] WebDriver driver = new FirefoxDriver();
所以,请你让我知道我错过的任何事情。
编辑:
build.xml的一部分:
<target name="init">
<ivy:resolve />
<ivy:cachepath pathid="compile.path" conf="compile" />
<ivy:cachepath pathid="test.path" conf="test" />
</target>
<target name="clean">
<delete dir="${target.dir}" />
</target>
<target name="prepare" depends="clean" description="Create working dirs and copy static files to work dir">
<mkdir dir="${target.dir}/WEB-INF/classes" />
<mkdir dir="${target.dir}/WEB-INF/classes-test" />
<!-- Copy static HTML and JSP files to work dir -->
<copy todir="${target.dir}">
<fileset dir="${web.home}" />
</copy>
</target>
<target name="compile" depends="prepare, init" description="Compile Java sources and copy to WEB-INF/classes dir">
<javac srcdir="${src.dir}" includeantruntime="false" debug="true" classpathref="compile.path" destdir="${target.dir}/WEB-INF/classes">
</javac>
<javac srcdir="${test.dir}" includeantruntime="false" debug="true" classpathref="test.path" destdir="${target.dir}/WEB-INF/classes-test">
<classpath>
<pathelement location="${target.dir}/WEB-INF/classes" />
</classpath>
</javac>
<copy todir="${target.dir}/WEB-INF/classes">
<fileset dir="${src.dir}" excludes="**/*.java" />
</copy>
</target>
和ivy.xml:
<ivy-module version="2.0">
<info organisation="org.apache" module="test-ivy" />
<configurations>
<conf name="runtime" />
<conf name="compile" extends="runtime" description="provides the
compiler" />
<conf name="test" description="Required for test only" extends="runtime"/>
</configurations>
<dependencies>
<dependency org="javax.servlet" name="servlet-api" rev="2.5" />
<dependency org="junit" name="junit" rev="4.12" />
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.48.2" conf="test-java->default"/>
<dependency org="log4j" name="log4j" rev="1.2.16" conf="compile->*" />
</dependencies>
</ivy-module>
与log4j的情况相同。我添加了依赖项,但是当我尝试创建Logger对象时,eclipse在使用代码辅助时没有列出log4j的记录器。
由于
答案 0 :(得分:0)
在build.xml中,您不是使用测试类路径编译测试类,而是编译类路径。
Classpathref应设置为test.path
<javac srcdir="${test.dir}" includeantruntime="false" debug="true" classpathref="test.path" destdir="${target.dir}/WEB-INF/classes-test">
<classpath>
<pathelement location="${target.dir}/WEB-INF/classes" />
</classpath>
</javac>
您应该为每个常春藤依赖项定义范围。像这样:
<!-- Compile time-->
<dependency org="log4j" name="log4j" rev="1.2.14" conf="compile->*"/>
<!-- test time-->
<dependency org="log4j" name="log4j" rev="1.2.14" conf="test->*"/>