Module 37: Having issue with running ANT with Maven | Selenium Forum
M
Posted on 10/09/2016
I have attached my MavenProejct in which I'm running JUNIT tests using the ANT.

The code executes fine with the command:
mvn.package

But throws error when I use the command:
mvn.compile
Or
ant run

Please suggets on the same.

I have attached the code and the error screen shots.

M
Replied on 15/09/2016

take look at this

http://stackoverflow.com/questions/25088899/selenium-webdriver-throws-exception-when-trying-to-run-via-ant


M
Replied on 18/09/2016

Hi Ashish,

I have gone through the link you have provided but I was unable to resolve the issue.
While running the Maven project using ANT my project complaining that I have multiple versions of ant detected in path for junit.
Its finding two ant jars one in
C:\Eclipse\Selenium Jars\apache-ant-1.9.7\lib\ant.jar [b:hgy3pwm9]- Path where I have my ant installed[/b:hgy3pwm9]
and one in
C:\Users\Vishvambruth JT\.m2\repository\org\apache\ant\ant\1.8.1\ant-1.8.1.jar -[b:hgy3pwm9] M2 Repository[/b:hgy3pwm9]

How can I make the change so that my project will find single ant.jar. Instead of multiple versions of ant.

I have pasted the command line output below:

run:
[mkdir] Created dir: C:\Eclipse\workspace\MyMavenProject\reports
[junit] WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:/C:/Eclipse/Selenium%20Jars/apache-ant-1.9.7/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/C:/Users/Vishvambruth%20JT/.m2/repository/org/apache/ant/ant/1.8.1/ant-1.8.1.jar!/org/apache/tools/ant/Project.class
[junit] Running com.testing.GoogleTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.247 sec
[junit] Test com.testing.GoogleTest FAILED
[junit] Running com.testing.YahooTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.491 sec
[junit] Test com.testing.YahooTest FAILED
[junitreport] Processing C:\Eclipse\workspace\MyMavenProject\reports\TESTS-TestSuites.xml to C:\Users\VISHVA~1\AppData\Local\Temp\null29233824
[junitreport] Loading stylesheet jar:file:/C:/Eclipse/Selenium%20Jars/apache-ant-1.9.7/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 605ms
[junitreport] Deleting: C:\Users\VISHVA~1\AppData\Local\Temp\null29233824

BUILD SUCCESSFUL
Total time: 18 seconds


M
Replied on 18/09/2016

[quote:3425xak3]How can I make the change so that my project will find single ant.jar. Instead of multiple versions of ant.

[/quote:3425xak3]

you have to delete one jar.


M
Replied on 19/09/2016

Hi Ashish,

Now I'm able to run my project using ant after I deleted the below .jar files from my .m2 repository

[b:2izrj0aq]Deleted - [/b:2izrj0aq]
C:\Users\Vishvambruth JT\.m2\repository\com\google\collections\google-collections\1.0\google-collections-1.0.jar

[b:2izrj0aq]Deleted - [/b:2izrj0aq]
C:\Users\Vishvambruth JT\.m2\repository\org\apache\ant\ant\1.8.2\ant-1.8.1.jar

But now I'm facing the issue while running my ant .bat file using the maven i.e. using [b:2izrj0aq]"mvn compile"[/b:2izrj0aq] command.
When I use the [b:2izrj0aq]"mvn compile"[/b:2izrj0aq] command the above jars which I deleted will get automatically downloaded and again my project complains that I have multiple versions of ant detected in path for junit.

Please suggest.


M
Replied on 20/09/2016

remove the jar from dependency of pom.xml also.


M
Replied on 20/09/2016

Below is my pom.xml. I have dependencies added for only Junit, TetsNG and Selenium Jars.

Which dependency you want me to remove.

[code:3nh7gfav]<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>WebDriverTest</groupId>
<artifactId>WebDriverTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.0-beta3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks name="runtheapp">

<!-- <property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>

<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="test classpath: ${test_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/> -->

<ant antfile="build.xml"/>
<exec
dir="${basedir}"
executable="${basedir}/testrunner.bat"
failonerror="true">
<arg line=""/>
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-antrun-plugin
</artifactId>
<versionRange>
[1.7,)
</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>[/code:3nh7gfav]


M
Replied on 20/09/2016

delete the files from selenium jar then

C:\Eclipse\Selenium Jars\apache-ant-1.9.7\lib\ant.jar


M
Replied on 21/09/2016

[b:3d88g0ax]If I delete the below file.[/b:3d88g0ax]
C:\Eclipse\Selenium Jars\apache-ant-1.9.7\lib\ant.jar
[b:3d88g0ax]Its complaining that:[/b:3d88g0ax]
ANT_HOME is set incorrectly or ant could not be located. Please set ANT_HOME.


[code:3d88g0ax]C:\Eclipse\workspace\MyMavenProject>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building WebDriverTest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WebDriverTest ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ WebDriverTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-antrun-plugin:1.7:run (default) @ WebDriverTest ---
Downloading: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.8.2/ant-1.8.2.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.8.2/ant-1.8.2.jar (1889 KB at 1491.6 KB/sec)
[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks

runtheapp:

usage:
[echo]
[echo] ant run will execute the test
[echo]
[exec]
[exec] C:\Eclipse\workspace\MyMavenProject>ant clean run
[exec] ANT_HOME is set incorrectly or ant could not be located. Please set ANT_HOME.
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.359 s
[INFO] Finished at: 2016-09-21T01:47:55-05:00
[INFO] Final Memory: 13M/121M
[INFO] ------------------------------------------------------------------------[/code:3d88g0ax]


M
Replied on 21/09/2016

change the environment variable ANT_HOME.


M
Replied on 21/09/2016

Do I need to change my ANT_HOME variable to ANT folder in M2 repository?


M
Replied on 21/09/2016

Do I need to chage the ANT_HOME to Ant folder in M2 repository?


M
Replied on 21/09/2016

[quote="vishruth.cse@gmail.com":fv0463lh]Do I need to chage the ANT_HOME to Ant folder in M2 repository?[/quote:fv0463lh]

where is Ant home located currently?


M
Replied on 21/09/2016

Currently its located below:
ANT_HOME = C:\Eclipse\Selenium Jars\apache-ant-1.9.7


M
Replied on 22/09/2016

are you running any other pom.xml apart from the one you showed me.


M
Replied on 22/09/2016

No I'm not running any pom.xml other than the one i showed you.

Attached my project if you want to take a look.


M
Replied on 22/09/2016

[quote:3o0n3718]Attached my project if you want to take a look.[/quote:3o0n3718]
preamble in not with project but your system configuration.

can you come on skype tomorrow(23 sept) at 12:20 pm


M
Replied on 23/09/2016

Hi Ashish,

I'm from USA and work in CST timings. Please let me know if its convenient for you to have the Skype session on Saturday/Sunday.

And let me know what time you can come to Skype So I will make my time accordingly.


M
Replied on 23/09/2016

what time are you available?


M
Replied on 23/09/2016

I'm online now. Can I come to skype now.