maven-antrun-plugin problems (with solutions)
During my JEasyTest digging, I stumbled upon few maven-antrun-plugin problems. Here they come (with solutions).
com.sun.tools.javac.Main is not on the classpath
At first I tried to run whole build.xml from maven, so that javac ant task was responsible for compilation of the project:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<tasks>
<ant antfile="${basedir}/build.xml">
<target name="runAllTests" />
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
After executing mvn test
I got this error:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing ant tasks
Embedded error: The following error occurred while executing this line:
/home/tomek/work_other/jet2/build.xml:33: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
The solution is to set this property somewhere at the beginning of ant build.xml
file:
<property name="build.compiler" value="extJavac"/>
Could not create task or type of type: junit / iajc
Now another error happened:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing ant tasks
Embedded error: The following error occurred while executing this line:
/home/tomek/work_other/jet2/build.xml:43: Could not create task or type of type: junit.
Ant could not find the task or a class this task relies upon.
After adding dependencies to maven-antrun-plugin the build went ok (I also added aspectjtools, because without it similiar error appears (Could not create task or type of type: iajc.
). At the end dependencies passed to ant looked like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.5.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<tasks>
<ant antfile="${basedir}/build.xml">
<target name="runAllTests" />
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
After adding aspectjtool dependency I needed to change taskdef
in build.xml
file from:
<taskdef resource="org/aspectj/antlib.xml" classpath="${lib.dir}/aspectjtools-1.5.3.jar"/>
to:
<taskdef resource="org/aspectj/antlib.xml" />
Well, that's it. Eventually I suceeded in doing almost everything from maven and thus all these dependecies become obsolete, and I got rid of them.
links
This used to be my blog. I moved to http://tomek.kaczanowscy.pl long time ago.
Saved the day :)
Nice write up. Was really helpful.
Bumped into this issue when
Bumped into this issue when using maven-antrun-plugin in my project.
Thank you.