Adding autoprefix-cli to ANT build - java

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>

Related

Error Failed to open properties file : AppManage.tra from Ant script

After building EAR file when i'm trying to extract XML file form the EAR i'm getting error [exec] Failed to open properties file : AppManage.tra
<property name="Appmanage" value="C:\tibco\etascbw513\tra\5.10\bin\AppManage.exe" />
<target name="extract">
<exec executable="${Appmanage}">
<arg value="-export"/>
<arg value="-ear"/>
<arg value="${workdir}\Deploy\EARs\${project}.ear"/>
<arg value="-out"/>
<arg value="${workdir}\Deploy\EARs\${project}.xml"/>
<arg value="-max"/>
</exec>
old Q : can someone share simple build.xml to create ear file from ant script
details : i'm able to pull repositories with the help ant script now i want to create EAR file from ant script for Tibco BW. can any one share simple demo .
try to solve this error using below steps.
try to check your environment variable path.
check TRA_HOME/bin/ using App manage utility.
This error "Failed to open properties file : AppManage.tra" occurs because the AppManage executable tries to look for AppManage.tra in the current execution directory and does not find it. In this particular case, the current execution directory would depend on where you are executing Ant from.
The correct way to avoid this error is to provide full path to the AppManage.tra file as an argument to the AppManage executable in the ant exec statement, as shown below, in the highlighted section (two new arguments are added "--propFile" and "full path to AppManage.tra"). Hope this helps.
<property name="Appmanage" value="C:\tibco\etascbw513\tra\5.10\bin\AppManage.exe" />
<target name="extract">
<exec executable="${Appmanage}">
<arg value="--propFile"/>
<arg value="C:\tibco\etascbw513\tra\5.10\bin\AppManage.tra"/>
<arg value="-export"/>
<arg value="-ear"/>
<arg value="${workdir}\Deploy\EARs\${project}.ear"/>
<arg value="-out"/>
<arg value="${workdir}\Deploy\EARs\${project}.xml"/>
<arg value="-max"/>
</exec>

Getting illegal character error while using closure-compiler.jar using ANT for r.js optimization

I am using closure compiler jar for minification in r.js optimization in windows environment.
While running this task using ANT exec, getting illegal character error but while running same task using .bat file it working fine.
ANT exec task
<target name="do-optimization" description="It will do optimization using r.js.">
<exec dir="." executable="java" failonerror="true">
<arg value="-jar" />
<arg path="${src.dir}/r-js/lib/rhino/js.jar" />
<arg path="${src.dir}/r-js/lib/closure/compiler.jar" />
<arg path="${src.dir}/r-js/dist/r.js" />
<arg value="-o"/>
<arg path="${src.dir}/r-js/build.js" />
</exec>
</target>
console output
do-optimization:
[exec] js: "C:\workspace\test\ui\r-js\lib\closure\compiler.jar", line 2: illegal character
[exec] js: ╝MOC ♦ META-INF/■╩ PK♥♦
[exec] js: ^
[exec] js: "C:\workspace\test\ui\r-js\lib\closure\compiler.jar", line 1: Compilation produced 1 syntax errors.
[exec]
BUILD FAILED
optimize.bat
java -classpath "r-js\lib\rhino\js.jar";"r-js\lib\closure\compiler.jar" org.mozilla.javascript.tools.shell.Main r-js/dist/r.js -o build.js
It doesn't seem that the Ant script is calling java the same way as the batch file. The exec task is calling the following command:
java -jar ${src.dir}/r-js/lib/rhino/js.jar ${src.dir}/r-js/lib/closure/compiler.jar ${src.dir}/r-js/dist/r.js -o ${src.dir}/r-js/build.js
which is clearly different than the one in the .bat file, i.e. the jars are not being added to the classpath properly.
In Ant, you can simply use the java task to run a Java class. Try using the following:
<java classname="org.mozilla.javascript.tools.shell.Main" failonerror="true">
<arg path="${src.dir}/r-js/dist/r.js" />
<arg value="-o"/>
<arg path="${src.dir}/r-js/build.js" />
<classpath>
<pathelement location="${src.dir}/r-js/lib/rhino/js.jar" />
<pathelement location="${src.dir}/r-js/lib/closure/compiler.jar" />
</classpath>
</java>

Change JDK for running <ANT> task from within build xml

I have build.xml which calls swfbuild.xml. I want parent build.xml to use IBM JDK 1.5 and swfbuild.xml to use Sun JDK 1.6
Is there any option in <ant> task to specify different JDK to use?
I tried setting JAVACMD like below but that doesn't work either
How can I use different JDK for swfbuild.xml?
<target name="Compile_SWF">
<exec executable="cmd">
<env key="JAVACMD" value="C:/Program Files/Java/jdk1.6.0_18" />
</exec>
<echo message="Start to Compile SWF content" />
<ant antfile="swfbuild.xml" target="swf-masterbuild" />
<exec executable="cmd">
<env key="JAVACMD" value="C:/IBM/SDP/runtimes/base_v61/java" />
</exec>
</target>
In each xml file, you can specify the executable to use inside the javac task. You must include the fork=yes in addition to the executable= parameter.
<javac fork="yes" executable="C:/Program Files/Java/jdk1.7.0_17/bin/javac">

Ant command line arguments

Program works fine when run with eclipse run configurations, but when run with ant, it is unable to parse int from args[0], which I do not understand. Full code is available here https://gist.github.com/4108950/e984a581d5e9de889eaf0c8faf0e57752e825a97
I believe it has something to do with ant,
target name="run" description="run the project">
java dir="${build.dir}" classname="BinarySearchTree" fork="yes">
<arg value="6 in.txt"/>
/java>
/target>
the arg value will be changed via the -D flag, as in ant -Dargs="6 testData1.txt" run.
Any help would be much appreciated, it is very frustrating.
You need to supply the arguments as two different arg values:
<target name="run" description="run the project">
<java dir="${build.dir}" classname="BinarySearchTree" fork="yes">
<arg value="6" />
<arg value="in.txt" />
</java>
</target>
You can also use the line attribute; From the ANT docs:
<arg value="-l -a"/>
is a single command-line argument containing a space character, not separate commands "-> l" and "-a".
<arg line="-l -a"/>
This is a command line with two separate arguments, "-l" and "-a".
Expanding epoch 's answer.
java task supports sysproperty and jvmarg.
For example (from ant java task page)
<java classname="test.Main"
fork="yes" >
<sysproperty key="DEBUG" value="true"/>
<arg value="-h"/>
<jvmarg value="-Xrunhprof:cpu=samples,file=log.txt,depth=3"/> </java>
So you could construct the args from the command line passed to ant.
<target name="run" description="run the project">
<java dir="${build.dir}" classname="BinarySearchTree" fork="yes">
<sysproperty key="testarg" value="${testarg}"
<arg value="${arg1}" />
<arg value="${arg2}" />
</java>
</target>
Now if you call ant with ant -Dtestarg=test1234 -Darg1=6 -Darg2=in.txt, then testarg will be available via property. Others will become normal arguments to the java program.

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