Ant include task - ant

Basic include task in ant does not work.
I just want to include the Eclipse generated build.xml in my custom build file.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." name="rizotek_server">
<include file="build.xml"/>
</project>
Both files are in the same directory.
I get exception.
BUILD FAILED
build_server.xml:3: Problem: failed to create task or type include
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
I looked at the Ant tutorials and I don't see any difference between the examples there and what I did.
What am I doing wrong?
Thanks everyone.
Kirill.

Import has a different result then include, and the way they work is quite different. So if you need include, then import may solve your problem or may not. That will depend on how you use it, but the two statements do very different things.
Besure that you're using a version of Ant that has support for include. It's probable that the version you're using doesn't. Include is only available in ant version 1.8.0 or later.

try the import task e.g.
<!-- importing.xml -->
<project name="importing" basedir="." default="...">
<import file="${path_to_imported}/imported.xml"/>
</project>

You have old version of Ant. I solved this problem by upgrading Ant.

Related

Jmeter 3.0 can't generate the ANT HTML report

I am on the verge of pulling all my hair out, someone please help me..
I am using JMeter 3.0 and am trying to generate the dashboard report from my jtl files, but I get the error -
result.jtl' does not contain the field names header, ensure the jmeter.save.saveservice.* properties are the same as when the CSV file was created or the file may be read incorrectly
my user.properites file contains -
jmeter.save.saveservice.output_format=csv
jmeter.save.saveservice.bytes=true
jmeter.save.saveservice.label=true
jmeter.save.saveservice.latency=true
jmeter.save.saveservice.response_code=true
jmeter.save.saveservice.response_message=true
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_counts=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true
jmeter.save.saveservice.timestamp_format=ms
jmeter.save.saveservice.timestamp_format=yyyy-MM-dd HH:mm:ss
jmeter.save.saveservice.print_field_names=true
these values are the same in the jmeter.properties file as well, just to ensure I haven't lost anything...
I really can't work out why I can't get the jtl to include the headers, I have followed every guide I can find, and I seem to be doing it right..
Can someone point to me what I am missing, or include a zipped version of their jmeter with it all working that I can try and point my ant project to?
Hope someone can help.
Double check <jmeter> section of your build.xml file. Default JMeter Ant Task assumes XML out put format for .jtl result files so if you have the following line:
<property name="jmeter.save.saveservice.output_format" value="xml"/>
just comment it out or delete it and your issue should be resolved.
I don't think JMeter Ant Task respects overrides via user.properties file, it is better to use jmeterproperties attribute or explicitly specify the relevant configuration in the Ant build file like:
<target name="test">
<jmeter
jmeterhome="${jmeter.home}"
testplan ="${testpath}/${test}.jmx"
resultlog="${testpath}/${test}.jtl">
<property name="jmeter.save.saveservice.output_format" value="csv"/>
<property name="jmeter.save.saveservice.print_field_names" value="true"/>
<property name="jmeter.save.saveservice.timestamp_format" value="ms"/>
<!--etc.-->
</jmeter>
</target>
I would also recommend choosing one of jmeter.save.saveservice.timestamp_format properties (either ms or yyyy-MM-dd HH:mm:ss as it might cause problems with the dashboard generation), having duplicate property names with different values is not a very good practice.
See Five Ways To Launch a JMeter Test without Using the JMeter GUI article for more information on running JMeter tests via Ant task and other ways of kicking off a JMeter test
I had noticed before you posted, but it is correct, the XML type was hardcoded in the build.xml, now I have changed that, all is working :)

Multiple configuration files for the ProGuard Ant task

I am using the ProGuard ant task, and everything is great, except that my ProGuard configuration file is huge. Also, different tasks use different ProGuard configuration files, and there is a lot of copy-pasting that I would like to refactor into separate .pro files.
<taskdef resource="proguard/ant/task.properties" classpath="C:/Program Files/proguard4.7/lib/proguard.jar"/>
<target name="obfuscated_jar" depends="raw_jar">
<proguard configuration="core.pro lib1.pro lib2.pro">
<outjar path="prog_obfuscated.jar"/>
</proguard>
</target>
The above doesn't work, because it treats the multiple .pro files as one big filename. I'm a known idiot w.r.t. ant, am I missing something obvious? Thanks!
You can create a single main .pro file that contains -include options pointing to your actual .pro files.
This answer isn't great, but it works...
<taskdef resource="proguard/ant/task.properties" classpath="C:/Program Files/proguard4.7/lib/proguard.jar"/>
<target name="obfuscated_jar" depends="raw_jar">
<concat destfile="proguard_temp.pro">
<filelist dir="." files="core.pro,lib1.pro,lib2.pro"/>
</concat>
<proguard configuration="proguard_temp.pro">
<outjar path="prog_obfuscated.jar"/>
</proguard>
<delete file="proguard_temp.pro"/>
</target>
Looks like only one file allowed in configuration attribute.
Edited
And attributes allowed only on <proguard> element. I have another possible solution. Try to concatenate your config-files into one with Ant concat-task and pass this temporary file to <proguard configuration=""> attribute.
Also, it's possible to modify ProGuardTask-class to accept several files as arguments and concatenate them later. And same result could be achieved with Ant macrodef .

Intellij IDEA doesn't recognized XJC task attributes

I have an ant build.xml file with XJC task definition:
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath>
<fileset dir="jaxb" includes="*.jar" />
</classpath>
</taskdef>
jaxb dir cotnains jaxb-xjc.jar with XJCTask class inside.
Then I call xjc task in some target:
<target name="mytarget">
<xjc target="src" package="com.p1.Person" header="false">
<schema dir="src/com/p1" includes="Person.xsd"/>
</xjc>
</target>
Intellij IDEA doesn't recognize the structure/schema of the xjc call and highlights all attributes (target, package, header) and containing elements (schema) in red.
If I choose Ant options and add jaxb-xjc.jar to additional class path list this doesn't help.
I use bundled Ant 1.8.2
The bad thing is that when I compile it in IDEA I get a lot of related errors, but when I run build script everything works fine. I want to suppress these errors.
Any ideas?
The answer comes from this comment in a related bug in the IDEA issue tracker.
http://youtrack.jetbrains.net/issue/IDEA-11248#comment=27-57354
For the XJCTask issues with IDEA, just use XJC2Task in your taskdef.
If you look at the source of XJC2Task, it has the setters exposed so that IDEA can resolve them:
http://grepcode.com/file/repo1.maven.org/maven2/com.sun.xml.bind/jaxb-xjc/2.1.13/com/sun/tools/xjc/XJC2Task.java#XJC2Task.setPackage%28java.lang.String%29
However, XJCTask is just a class to dynamically delegate to JAXB1 or JAXB2 on the fly so IDEA is unable to resolve these properties since the class you are defining in the taskdef doesn't have the setters on it.
http://grepcode.com/file/repo1.maven.org/maven2/com.sun.xml.bind/jaxb-xjc/2.1.13/com/sun/tools/xjc/XJCTask.java#XJCTask.getCoreClassName%28%29
Edit:
Basically in JAXB2, XJCTask doesn't actually contain the task - it delegates to the actual task XJC2Task.
Here are some better links to the source:
XJCTask in JAXB 1
http://java.net/projects/jaxb/sources/version1/content/trunk/jaxb-ri/xjc/src/com/sun/tools/xjc/XJCTask.java?rev=197
XJCTask in JAXB2
http://java.net/projects/jaxb/sources/version2/content/trunk/jaxb-ri/xjc/facade/com/sun/tools/xjc/XJCTask.java?rev=3863
XJC2Task in JAXB2
http://java.net/projects/jaxb/sources/version2/content/trunk/jaxb-ri/xjc/src/com/sun/tools/xjc/XJC2Task.java?rev=3863
If you look at your jaxb-xjc-ri-2.x-xx.jar you will see that it contains a package called "1/com/sun/tools/xjc/"
This is what gets called from the XJCTask in JAXB2 if you run your ant task with setting the version to 1.0.
I expect it was put in to allow easier transitions to v2 from v1 back in the day.
XJC2Task is what is called if you are using v2.
Realistically you aren't going to set it to 1.0 so you might as just call the XJC2Task directly.

Execute Ant action always and independently from target

Is there a way to specify actions like <copy> in an Ant buildfile that get executed every time the build file gets read by ant (regardless of the target which is called)?
The background is: I want a *.properties-file to be automatically created from a template when it's not present. I know, I could specify a target which does this and then include it at the root of the dependency-tree but maybe there is a more elegant solution. Because actually the problem is a bit more complex: the ant file where the *.properties-file is read-out is imported by other build files and I don't want to cross-reference targets between them.
I hope I explained my problem sufficiently. In cases of questions do not hestitate to ask.
This is my first posting here. Hope you can help - Greetings from Germany, Ben.
Just put the code at the top of the file, outside of a target definition.
<project name="myproject" default="mytarget" basedir=".">
<echo message="Hello there." />
<target name="mytarget">
<!-- Do stuff. -->
</target>
<target name="myothertarget">
<!-- Do other stuff. -->
</target>
</project>
In this case the echo will get executed once before any target, regardless of which target is invoked.

What is the best way to compile J2ME and J2SE apps from the same codebase?

I'm trying to build an app for both J2ME and J2SE. The presentation code will obviously be different, but I'm hoping to keep the logic common, as much as possible.
My plan is to use Ant or Antenna's preprocessor to select either the J2ME or J2SE Graphics object, with that class being the only intersection between my logic and display code. All I need is to swap a line or two of imports in a few files during my Ant/Antenna build task.
I'd like some advice on how to get this set up.
I've currently got two Eclipse projects, one J2ME and one J2SE. I have a couple ideas for how I could set up the preprocessor:
Have the J2SE code be the default, and only preprocess the J2SE code to swap in the J2SE specific imports
Use the Antenna preprocessor for both the J2ME and J2SE projects
Use Ant text substitution to make the necessary source modifications
i. looks hard to get set up right
ii. feels a bit kludgy
iii. seems least bad, because I don't see myself ever needing to use much more than a few conditional imports.
Has anyone had experience with this sort of thing? Some advice would be much appreciated.
Both app versions have different ways to startup, right? One time it's a MIDlet and the other time a Java class with a static main method. In that case I don't see the requirement to use preprocessing. Both startup implementations could access the common code base and hand over either the J2ME or J2SE "graphics" object which implements an interface known to the common code base. This way the common code base does not need to know implementation details, it just needs the interface for the representation part.
BTW .. I had a similar situation some time ago and I felt more comfortable with setting up 3 Eclipse projects, a J2ME, a J2SE and a common logic project (technically also a J2ME project). This helps to prevent class name conflicts between the J2ME-/J2SE-only parts.
Antenna should do for most cases. The advantage of using a single source for both J2SE and J2ME is that you are saved from the maintenance of source code and you also eliminate the possibility of bugs creeping in. I too had similar problems, but I had to write a custom preprocessor that suited my need. But for most purposes antenna does the job beautifully
Edited: Sample build file
<project name="SomeProject" default="buildJ2ME" basedir="..">
...
...
...
<taskdef name="jadUpdater" classname="net.jxta.j2me.tools.Jad" classpath="${lib.dir}/jxta-tools.jar"/>
<taskdef resource="proguard/ant/task.properties" classpath="${lib.dir}/proguard.jar" />
<taskdef resource="antenna.properties" classpath="${lib.dir}/antenna-bin-1.0.2.jar" />
<macrodef name="preprocess">
<attribute name="source"/>
<attribute name="dest"/>
<attribute name="symbols"/>
<sequential>
<wtkpreprocess
version="2"
srcdir="#{source}"
destdir="#{dest}"
symbols="#{symbols}"
printsymbols="true">
</wtkpreprocess>
</sequential>
</macrodef>
<target name="compile" depends="init">
<copy todir="${temp.dir}/src" >
<fileset dir="${src.dir}"/>
</copy>
<preprocess source="${temp.dir}/src" dest="${temp.dir}/preprocessed" symbols="${symbols}"/>
<javac srcdir="${temp.dir}/preprocessed"
destdir="${temp.dir}/classes"
bootclasspath="${bootclasspath}"
classpath="${lib.dir}"
debug="off"
source="1.3"
target="1.1" />
<antcall target="jarForObfuscate"/>
</target>
<target name="buildJ2ME" depends="clean">
<property name="symbols" value="J2ME1,J2ME2"/>
<antcall target="compile"/>
</target>
<target name="buildJ2SE">
<property name="symbols" value="J2SE1,J2SE2"/>
<antcall target="compile"/>
</target>
...
...
...
</project>
Hope this helps!
I've done it once with all j2me libraries replaced by my own fakes. These fakes would call all the needed j2se lib calls.
Sounds like a lot of work, but actually a lot of calls are similar, and you are probably not using everything so you only need to create a small subset of the available j2me classes
Endresult: source code which nearly doesn't need any #ifdef stuff

Resources