How to run mvn clean install from build.xml - java

I have all other modules on ant while a new module has been added on maven. So, I have created build_dl.xml file in the same directory level as pom.xml
<project name="Income">
<target name="mvn">
<exec dir="." executable="sh">
<arg line=" -c 'mvn clean install'" />
</exec>
</target>
</project>
On executing the build file ant -buildfile build_dl.xml I am getting logs saying BUILD SUCCESSFUL
Total time: 0 seconds but actually the pom.xml doesnt gets executed and no target folder is created. Could anyone please help where I am going wrong.

Try running mvn directly as the executable, and pass your args individually with value, instead of all at once with line:
<project name="Income">
<target name="mvn">
<exec dir="." executable="mvn">
<arg value="clean" />
<arg value="install" />
</exec>
</target>
</project>

Related

Ant with Jar Target

I need help, to understand the problem of jar packaging with ant. Here my simple code:
<target name="build" depends="compile,test">
<jar
basedir="${bin}/swing.gui"
destfile="${mod}/swing.gui.jar">
<manifest>
<attribute name="Main-Class" value="swing.main.Main"/>
</manifest>
</jar>
</target>
The little program is modularized and as you can see the module swing.gui should be packaged in a jar file. The problem here, when I try to start the module with:
java --module-path bin/mod --module swing.gui
It does not work. The error message says that there is no MainClass attribute and I should try -m / instead.
When I execute this line on the console:
jar --create --file=bin/mod/swing.gui.jar --main-class=swing.main.Main -C bin/src/swing.gui .
It just works! Is that a bug in ant?
Not a bug, exactly. Ant is just doing what you told it to do.
The Main-Class manifest attribute is not used by module loaders. The --main-class option of jar has nothing to do with manifests; it sets a binary class attribute on the jar’s module-info.class entry.
So, your Ant build file is doing something entirely different from what your jar command is doing.
Until Ant’s <jar> task has direct support for this, the workaround is to call the JDK’s jar command directly. Something like this:
<condition property="exec-suffix" value=".exe" else="">
<os family="windows"/>
</condition>
<property name="jar.tool"
location="${java.home}/bin/jar${exec-suffix}"/>
<exec executable="${jar.tool}" failonerror="true">
<arg value="-u"/>
<arg value="-f"/>
<arg file="${mod}/swing.gui.jar"/>
<arg value="-e"/>
<arg value="swing.main.Main"/>
</exec>

Adding autoprefix-cli to ANT build

I am trying to add autoprefix-cli to my ANT build. Below is my code.
<target name="auto">
<apply executable="autoprefixer-cli.bat" verbose="true" force="true" failonerror="true">
<arg value="-d" /> <!-- Turn on verbose -->
<arg value="prefix" />
<arg value="*.css" />
</apply>
</target>
When i do a ant build, it gives me an error saying resource not specified.
BUILD FAILED
D:\tempTest\AntTestProject\build.xml:25: no resources specified
Note: I can access autoprefix-cli from command line, its installed with -g flag and also it works when i directly use it from commandline.
The apply task basically loops the exec task on a batch of resources (files, directories, URLs, etc). If you only want to run one command, use exec instead.
However, you will likely also need to alter your command. From Ant's exec task documentation:
Note that .bat files cannot in general by executed directly. One
normally needs to execute the command shell executable cmd using the
/c switch.
https://ant.apache.org/manual/Tasks/exec.html
So instead you should have:
<exec executable="cmd" verbose="true" force="true" failonerror="true">
<arg value="/c" />
<arg value="autoprefixer-cli.bat" />
<arg value="-d" />
<arg value="prefix" />
<arg value="*.css" />
</exec>

Trying to use exec executable in ant to run R

I am using the following open source version of image J in an experiment:
https://github.com/pcj/arterioj
it uses ANT.
Of of the ant targets is:
stats
<!-- ================================================================ -->
<!-- Stats and plot generation tasks -->
<!-- ================================================================ -->
<target name="stats">
<exec executable="R">
<arg line="--vanilla --no-readline --quiet --slave --file=${basedir}/ldip-data.R --args"/>
</exec>
</target>
when I try to use this target I get the following build error message:
BUILD FAILED
/Users/James/ArterioJ/build.xml:179: Execute failed: java.io.IOException: Cannot run program "R" (in directory "/Users/James/ArterioJ"): error=2, No such file or directory
I am unsure how to fix this. I have tried to copy the R package into the /users/James/ArterioJ directory to see if that would help but to no effect.
Thanks
You might want to specify the full path of the R executable, for instance:
<property name="r.home" value="/home/me/R_INSTALL"/>
<target name="stats">
<exec executable="${r.home}/R">
<arg line="--vanilla --no-readline --quiet --slave --file=${basedir}/ldip-data.R --args"/>
</exec>
</target>
Alternatively, if the path to the executable is part of the PATH environment variable, you could just add the searchpath="true" attribute to the exec task:
<exec executable="R" searchpath="true">
<arg line="--vanilla --no-readline --quiet --slave --file=${basedir}/ldip-data.R --args"/>
</exec>
Here is an extract from the Ant documentation about searchpath:
When this attribute is true, then system path environment variables
will be searched when resolving the location of the executable

using ant svn task to get the version of a working copy?

Is there a way use the svn ant task to get the svn revision number of a working copy and put it into a variable?
I would like to add an entry in my Java manifest file which includes the svn revision number, e.g. 0.9.65361 where 65361 is the revision number.
Aha, I found this idea, which depends only on the svnversion command-line utility in SVN.
<project name="ant-exec-example" default="svnversion" basedir=".">
<target name="svnversion">
<exec executable="svnversion" outputproperty="svnversion" />
<echo message="SVN Version: ${svnversion}"/>
</target>
</project>
Here's where it captures the version in an ant property:
<exec executable="svnversion" outputproperty="svnversion" />
There are a couple of ways -
Use a utility - I believe you are looking for this - https://code.google.com/p/svntask/ I have used it for some side
projects and it works well.
Use commandline utility. - "svn info http://svn.myweb.com/myproject". To use this method simply create a
batch file and put this command in the batch file. Then call this
batch file from your ant task and get the revision number from the
text by searching for that starts with line "Revision:". Or you can
just dump the whole result.
Here is my variant to bundle svn revisions info within the application artifact:
<target name="svn_revisions">
<hostinfo prefix="HOST"/>
<echo file="${dir.out}/.revisions" message="Built by ${user.name} on ${HOST.NAME}${line.separator}"/>
<exec dir="${basedir}" executable="svn" output="${dir.out}/.revisions" append="true">
<arg line="info"/>
</exec>
<exec dir="${basedir}" executable="svn" output="${dir.out}/.revisions" append="true">
<arg line="status -u"/>
</exec>
</target>
<target name="build-war" depends="compile, svn_revisions">
<war basedir="web" file="${dir.out}/ROOT.war" webxml="web/WEB-INF/web.xml">
<!-- main stuff -->
<zipfileset dir="${dir.out}" prefix="META-INF" includes=".revisions"/>
</war>
</target>

Ant & Mercurial

I am trying to add some tag information in my ant script using the following target but I get an error (Result=-1) and hg tells me it does not recognise the command:
<target name="-post-init">
<exec outputproperty="hg.tag" executable="hg">
<arg value="parents --template {latesttag}+{latesttagdistance}" />
</exec>
</target>
If I only include value="parents" it works fine.
If I run the command line hg parents --template {latesttag}+{latesttagdistance} it works fine too.
Any ideas on what is wrong in my syntax?
Just tried this and it works fine:
<exec outputproperty="hg.tag" executable="hg">
<arg value="parents" />
<arg value="--template" />
<arg value="{latesttag}+{latesttagdistance}" />
</exec>
I needed to split the arguments.

Categories