Maven antrun plugin classpath issue
Posted by doubleA on September 4, 2007
Last week, I setup Selenium in my multi module maven project according to this Raible Designs post. All was working well as long as I built my project from the functional-tests module.
As soon as I ran a full project build from the parent POM, I saw the following error:
Selenium Server started
[INFO] [antrun:run {execution: launch-selenium}]
[INFO] Executing tasks
[taskdef] Could not load definitions from resource selenium-ant.properties. It could not be found.
[INFO] ————————————————————————
[ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO] Error executing ant tasks
Embedded error: Could not create task or type of type: selenese.
Ant could not find the task or a class this task relies upon.
This is common and has a number of causes; the usual
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file:
– You have misspelt ’selenese’.
Fix: check your spelling.
– The task needs an external JAR file to execute
and this is not found at the right place in the classpath.
Fix: check the documentation for dependencies.
Fix: declare the task.
– The task is an Ant optional task and the JAR file and/or libraries
implementing the functionality were not found at the time you
yourself built your installation of Ant from the Ant sources.
Fix: Look in the ANT_HOME/lib for the ‘ant-’ JAR corresponding to the
task and make sure it contains more than merely a META-INF/MANIFEST.MF.
If all it contains is the manifest, then rebuild Ant with the needed
libraries present in ${ant.home}/lib/optional/ , or alternatively,
download a pre-built release version from apache.org
– The build file was written for a later version of Ant
Fix: upgrade to at least the latest release version of Ant
– The task is not an Ant core or optional task
and needs to be declared using .
– You are attempting to use a task defined using
or but have spelt wrong or not
defined it at the point of use
Remember that for JAR files to be visible to Ant tasks implemented
in ANT_HOME/lib, the files must be in the same directory or on the
classpath
Please neither file bug reports on this problem, nor email the
Ant mailing lists, until all of these causes have been explored,
as this is not an Ant bug.
[INFO] ————————————————————————
[INFO] For more information, run Maven with the -e switch
[INFO] ————————————————————————
[INFO] Total time: 2 minutes 9 seconds
[INFO] Finished at: Tue Sep 04 07:08:47 MDT 2007
[INFO] Final Memory: 19M/34M
[INFO] ————————————————————————
After digging into the Selenium jars and trying to find the properties file in question, I stumbled acrosss this Jira issue for the plugin. The last comment from 7/3/07 gave me a new hope.
Based on the comment, I looked at my POMs and found the first instance the reactor would be using in the multi-module build. I added the Selenium dependencies :
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>org.openqa.selenium.server</groupId>
<artifactId>selenium-server</artifactId>
<version>0.9.2-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>org.apache.ant</artifactId>
<groupId>ant</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Presto, the build worked. It turns out the classpath or loading process for the plugin was getting confused when 2 modules defined the antrun plugin. My core module uses the antrun plugin to copy configuration files for each server environment. The functional-test module uses antrun for Selenium. It’s a little quirky to add the Selenium dependencies to my core module POM that doesn’t use Selenium, but with a healthy dose of comments, it’s manageable and best of all, it works.