Sun WTK Preverify failing in J2ME- java/lang/NoClassDefFoundError - ant

I have written ANT script to preverify the classes.,
<property name="wtkHome" location="C:/WTK2.5.2"> </property>
<property name="midp_lib" value="${wtkHome}/lib/midpapi21.jar"></property>
....
........
<property name="build" value="build"/>
.....
......
<target name="preverify">
<mkdir dir="${build}/preverified"/>
<exec executable="${wtkHome}/bin/preverify">
<arg line="-classpath ${wtkHome}/lib"/>
(or) <arg line="-classpath ${midp_lib}"/>
<arg line="-d ${build}/preverified"/>
<arg line="${build}/classes"/>
</exec>
</target>
When the above script executes, it is not able to find the midp classes in the classpath, so it's showing the error,
[exec] Error preverifying class first.MCCanvas
[exec] java/lang/NoClassDefFoundError: javax/microedition/lcdui/Canvas
[exec] Result: 1
But the required libraries are in the classpath, Please note compilation is fine for the MIDlet and Canvas classes!

Why don't you use Antenna? http://antenna.sourceforge.net/
Your build script would use:
<wtkpreverify cldc="CLDC-1.0" srcdir="${build}/classes" destdir="${build}/preverified" classpath="${wtk.home}/lib/cldcapi11.jar;${wtk.home}/lib/midpapi20.jar" />

Try with backslashes "\"
<arg line="-classpath C:\WTK2.5.2\lib\midpapi21.jar"/>

Related

Ant exec, How to arg

So I have the below build file:
<target name="test">
<echo message="test"></echo>
<exec executable="C:\Users\Abc\Desktop\cmd.bat" >
<arg value="exit"/>
<arg value="mkdir C:\Users\Abc\Desktop\ant\test"/>
</exec>
</target>
I thought it would create a test folder there but its not. It pops out another command prompt window, I thought the exit would close that but it doesn't. I'm not sure what I am doing wrong.
The content of bath script test1.bat:
#echo off
echo %1
And ant's build.xml:
<target name="test">
<echo message="test"></echo>
<exec executable="C:\Users\AAA\Desktop\ant\test1.cmd">
<arg value="hello"/>
</exec>
</target>
As per the official 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
Follow this format instead:
<target name="help">
<exec executable="cmd">
<arg value="/c"/>
<arg value="ant.bat"/>
<arg value="-p"/>
</exec>
</target>
Source: https://ant.apache.org/manual/Tasks/exec.html

No output running yui-compressor from Ant

I'm going to minify my js files by yuicomressor via ant, I wrote this:
<property name="concat-js-file-name" value="main.concat.js"/>
<property name="concat-js-file-path" value="${temp-folder}/js/${concat-js-file-name}"/>
<property name="yui-jar-path" value="lib/yuicompressor-2.4.7.jar"/>
<target name="minification" depends="concatation">
<echo>---Minification is started</echo>
<java jar="${yui-jar-path}" fork="true">
<arg value="${concat-js-file-path}"/>
<arg value="-o minified.js"/>
</java>
<echo>---Minification is finished successfully...</echo>
</target>
The problem is the output file is not generated!
Any idea?
You should set <java ... failonerror="true"/> and increase the noiselevel to see what's going on, means start your ant build with ant -f yourbuild.xml -debug
Actually, after some tries I found a solution:
I used <arg line="-o outputfile inputfile"/> instead, and it worked.
I suggest using <arg value="..."> instead of <arg line="...">. <arg value="..."> ensures that each command line argument has quotes around it, if necessary.
In the case of yui-compressor, the "-o" and "<file>" arguments should each go in their own <arg value="..."> elements:
<java jar="${yui-jar-path}" fork="true">
<arg value="-o"/>
<arg value="minified.js"/>
<arg value="${concat-js-file-path}"/>
</java>

JSCover - Excluding coverage files

Currently trying to get JSCover to exclude js files that are used as libraries. I have a set of ant scripts below which will
start the JSCover server
Run & Generate Json report
Stop the server
Finally, i have a shell command to convert the Json file to LCov so that i can use it with sonarqube. I also get coverage in jscoverage.html but it includes every file under web/ which is something i do not want. Image below
Ant scripts below:
<target name="jstest-start">
<java jar=".../JSCover.jar" fork="true" spawn="true">
<arg value="-ws"/>
<arg value="--report-dir=coverage"/>
<arg value="--document-root=web"/>
<arg value="--port=8082"/>
<!-- Aim is to exclude folder js under web/ as it contains libraries, not source code. Currently does not work -->
<arg value="--no-instrument=web/js/"/>
<arg value="--no-instrument=js/"/>
</java>
<waitfor maxwait="5" maxwaitunit="second" checkevery="250" checkeveryunit="millisecond" timeoutproperty="failed">
<http url="http://localhost:8082/jscoverage.html"/>
</waitfor>
<fail if="failed"/>
</target>
<target name="jstest-run">
<exec dir="/usr/local/CI/phantomjs/bin/" executable="phantomjs" failonerror="true">
<arg line=".../run-jscover-qunit.js http://localhost:8082/index.html"/>
</exec>
</target>
<target name="jstest-stop">
<get src="http://localhost:8082/stop" dest="stop.txt" />
</target>
<target name="jstest" description="Run javascript tests">
<antcall target="jstest-start"/>
<antcall target="jstest-run"/>
<antcall target="jstest-stop"/>
</target>
My folder structure is:
And finally, my sonar standalone analysis settings:
So, what seems to be happening is that JSCover is recursively reading for all js files and i cannot prevent that from sonar or ant.
Can anyone shed some light?
<arg value="--no-instrument=/js/"/>
should work, and to remove the test itself,
<arg value="--no-instrument=/test/"/>
The paths are as seen by the web-server, so the 'web' prefix in:
<arg value="--no-instrument=web/js/"/>
has no effect.
i have resolved my own issue by correcting the shell command which generates an LCOV report.
java -cp JSCover.jar jscover.report.Main --format=LCOV /usr/local/CI/jenkins/workspace/PhantomJS/coverage/phantom/ /usr/local/CI/jenkins/workspace/PhantomJS/web/
Prior to this, the SRC-DIR and REPORT-DIR were the same which was an error on my part. As far as i can understand, SRC-DIR should point to the source folder and REPORT-DIR should point to where the lcov file exists.
I hope this helps someone

How to add all files in a fileset as an argument to the exec task?

I'm trying to provide all *.cpp files in a folder to the c++ compiler through ant. But I get no further than ant giving gpp a giant string containing all the files. I tried to prove it by using a small test application:
int main( int argc, char**args ){
for( --argc; argc != 0; --argc ) printf("arg[%d]: %s\n",argc,args[argc]);
}
With the ant script like this:
<target name="cmdline">
<fileset id="fileset" dir=".">
<include name="*"/>
</fileset>
<pathconvert refid="fileset" property="converted"/>
<exec executable="a.exe">
<arg value="${converted}"/>
</exec>
</target>
My a.exe's output is this:
[exec] arg[1]: .a.cpp.swp .build.xml.swp a.cpp a.exe build.xml
Now here's the question: how do I provide all files in the fileset individually as an argument to the executable?
This is what the apply task in ANT was designed to support.
For example:
<target name="cmdline">
<apply executable="a.exe" parallel="true">
<srcfile/>
<fileset dir="." includes="*.cpp"/>
</apply>
</target>
The parallel argument runs the program once using all the files as arguments.
Found it: the difference seems to lie in arg value vs. arg line.
<arg line="${converted}"/>
resulted in the expected output:
[exec] arg[5]: C:\cygwin\home\xtofl_2\antes\build.xml
[exec] arg[4]: C:\cygwin\home\xtofl_2\antes\a.exe
[exec] arg[3]: C:\cygwin\home\xtofl_2\antes\a.cpp
[exec] arg[2]: C:\cygwin\home\xtofl_2\antes\.build.xml.swp
[exec] arg[1]: C:\cygwin\home\xtofl_2\antes\.a.cpp.swp
Based on this article, here is the complete code illustrating the use of the pathconvert task:
<target name="atask">
<fileset dir="dir" id="myTxts">
<include name="*.txt" />
</fileset>
<pathconvert property="cmdTxts" refid="myTxts" pathsep=" " />
<apply executable="${cmd}" parallel="false" verbose="true">
<arg value="-in" />
<srcfile />
<arg line="${cmdTxts}" />
<fileset dir="${list.dir}" includes="*.list" />
</apply>
</target>
Above code assumes there are no spaces in the paths.
To support spaces in paths, change above pathconvert line to:
<pathconvert property="cmdTxts" refid="myTxts" pathsep="' '" />
and arg line to:
<arg line="'${cmdTxts}'"/>
Source: Converting an Ant fileset to multiple apply args.
Have you looked at the ant cpptasks? This would allow you to integrate C++ compilation into your Ant build in a more Ant-centric fashion. For example, specifying files to be compiled using a fileset.
Here is the example (compatible with Ant 1.6 or later)::
<project name="hello" default="compile" xmlns:cpptasks="antlib:net.sf.antcontrib.cpptasks">
<target name="compile">
<mkdir dir="target/main/obj"/>
<cpptasks:cc outtype="executable" subsystem="console" outfile="target/hello" objdir="target/main/obj">
<fileset dir="src/main/c" includes="*.c"/>
</cpptasks:cc>
</target>
</project>

Running a BAT file from ANT

I have gone through number of posts on the very forum but couldn't sort it out. I am trying to run a BAT file from ANT script. The folder hierarchy is like this
- Project
| - build.xml
| - build-C
| | - test.bat
The ANT file that i wrote so for is
<project name="MyProject" basedir=".">
<property name="buildC" value="${basedire}\build-C" />
<exec dir="${buildC}" executable="cmd" os="Windows XP">
<arg line="/c test.bat"/>
</exec>
</project>
The bat file content is
echo In Build-C Test.bat
It says that build failed .. :s i dun know what wrong am i doing ?
<property name="buildC" value="${basedire}\build-C" />
This should be ${basedir} I guess? Use
<echo>${buildC}</echo>
to make sure the dir is correct.
And shouldn't
<exec dir="${buildC}" executable="test.bat" os="Windows XP" />
do the job?
Hopefully this will help expand on the already given/accepted answers:
I suggest executing cmd with the batch script as a parameter:
<exec failonerror="true" executable="cmd" dir="${buildC}">
<arg line="/c "${buildC}/test.bat""/>
</exec>
Not sure if it is necessary to use the absolute path "${buildC}/test.bat" since dir is specified, but I put it just in case. It might be enough to use /c test.bat.
My project executes a batch script on Windows operating systems & a shell script on all others. Here is an example:
<target name="foo">
<!-- properties for Windows OSes -->
<condition property="script.exec" value="cmd">
<os family="windows"/>
</condition>
<condition property="script.param" value="/c "${basedir}/foo.bat"">
<os family="windows"/>
</condition>
<!-- properties for non-Windows OSes -->
<property name="script.exec" value="sh"/>
<property name="script.param" value=""${basedir}/foo.sh""/>
<echo message="Executing command: ${script.exec} ${script.param}"/>
<exec failonerror="true" executable="${script.exec}" dir="${basedir}">
<arg line="${script.param}"/>
</exec>
</target>

Resources