I'm using J2ME Polish version 2.0.7 together with ant to build my Midlet application. In order to specifcy the main-class, name and icon of the application, the J2ME Polish documentation suggests that I use the midlet element inside the build element.
<build usePolishGui="false" >
<midlet name="My Killer App." icon="/logo.png" class="com.foo.MidletMain" />
...
</build>
however in the resulting .jad file only the classname is taken into account when I build my Midlet.
MIDlet-1: MidletMain,,com.foo.MidletMain
Can someone figure out what I'm doing wrong?
No it must be in the info section of the j2mepolish target:
<project ...>
<target name="j2mepolish" ...>
<j2mepolish>
<info ... icon="xxx.png">
What you will need to do is this:
<j2mepolish>
.....
<build>
...
<jad>
<attribute name="MIDlet-Icon" value="/icon.png" />
<jad>
</build>
Your icon would work!
Related
To eliminate redundancy in my ant build.xml files, I decided out-factor the repeated targets into mytargets.xml file, publish it to to the artifact repository, and then import it in the following way:
<import>
<url url="http://mycompany.com/artifacts/mycompany.com/mytargets/1.2.3/mytargets-1.2.3.xml"/>
</import>
There are two things I don't like about this approach:
mytargets-1.2.3.xml never appears anywhere on the disk where I can easily look at it.
I absolutely need access to http://mycompany.com/artifacts in order to do anything in the project---it completely undermines offline work.
So, I tried creating a setup target to fetch a local copy of mytargets.xml and adjusted my <import> to use this local copy.
<import file="${basedir}/antlib/mytargets/mytargets.xml"/>
However, as you have probably guessed, I cannot even execute my setup my target after adjusting my <import> in this way because the file does not yet exist:
Buildfile: /home/me/myproject/build.xml
BUILD FAILED
/home/me/myproject/build.xml:265: Cannot find /home/me/myproject/antlib/mytargets/mytargets.xml imported from /home/me/myproject/build.xml
Adding optional="true" to the <import> only defers the problem to the first target that depends upon mytargets.xml.
I looked at https://ant.apache.org/manual/Types/antlib.html, but this approach does not appears to permit you to define a <target>.
So, how does someone share bits of ant XML across multiple projects? Am I already doing it the 'one true way'? Or, is there a better way?
If you're mainly just trying to avoid download the remote copy when you have a local copy already available, you can try something like this:
<condition property="mytargets.xml.available">
<available file="${basedir}/antlib/mytargets/mytargets.xml" />
</condition>
<target name="setup" unless="mytargets.xml.available">
<get
src="http://mycompany.com/artifacts/mycompany.com/mytargets/1.2.3/mytargets-1.2.3.xml"
dest="${basedir}/antlib/mytargets"
/>
</target>
<target name="main" depends="setup">
<import file="${basedir}/antlib/mytargets/mytargets.xml" />
...
</target>
So, it seems to me that <target> is inherently local and not intended for reuse. On the other hand, <macrodef> appears intended for reuse.
Here is the 'library', mymacros.xml:
<?xml version="1.0"?>
<antlib>
<macrodef name="mymacro">
...
</macrodef>
</antlib>
Here is the client, myproject/build.xml:
<?xml version="1.0"?>
<project name="myproject">
<target name="mytarget">
<mymacro/>
</target>
<taskdef file="mymacros.xml"/>
</project>
Unlike <import> and <include>, <taskdef> will not cause the build to fail immediately if mymacros.xml is missing, which gives you the opportunity to download it.
I'm trying to get Jasper Reports working from my app in VB.Net. So, after considering many options, I decided to create a small program in java to launch it, and reference it in my .Net project, using JNI4NET.
I don't know if I'm doing something wrong, but, when I launch the proxygen tool, it gives me a "OK/Completed" message, it creates two directories, java and csharp, with two files that I think are the two proxies.
The problem comes when I follow the Wiki instructions(https://github.com/jni4net/jni4net/wiki/Generating-Proxies) and there says that it should be a "build.cmd" file that creates the dll that will be included later in my project. I don't have that file. What am I missing?
I launched the proxy with the command line .\proxygen.exe ProxyGenJasperTest.xml, being the xml:
<?xml version="1.0" encoding="utf-8" ?>
<jni4net-proxygen xmlns="http://jni4net.sf.net/0.8.8.0/toolConfig.xsd">
<!-- Location where .java files will be generated into. It's relative or absolute path. -->
<TargetDirJvm>java</TargetDirJvm>
<!-- Location where .cs files will be generated into. It's relative or absolute path. -->
<TargetDirClr>csharp</TargetDirClr>
<!-- List of class paths (.jar files or directories) which define known classes for generator-->
<ClassPath Path="lib/com.springsource.com.informix.jdbc-3.0.0.JC3.jar"/>
<ClassPath Path="lib/commons-beanutils-1.9.2.jar"/>
<ClassPath Path="lib/commons-collections-3.2.2.jar"/>
<ClassPath Path="lib/commons-digester-2.1.jar"/>
<ClassPath Path="lib/commons-logging-1.2.jar"/>
<ClassPath Path="lib/ecj-4.3.1.jar"/>
<ClassPath Path="lib/groovy-all-2.4.5.jar"/>
<ClassPath Path="lib/itext-2.1.7.jar"/>
<ClassPath Path="lib/jasperreports-6.2.2.jar"/>
<ClassPath Path="lib/jasperreports-fonts-6.2.2.jar"/>
<ClassPath Path="lib/jasperreports-functions-6.2.2.jar"/>
<ClassPath Path="lib/jasperreports-javaflow-6.2.2"/>
<ClassPath Path="lib/joda-time-2.4.jar"/>
<ClassPath Path="lib/ojdbc6.jar"/>
<ClassPath Path="JasperTest.jar"/>
<!-- List of Java classes which should have proxy generated -->
<JavaClass TypeName="jaspertest.JasperTest"/>
</jni4net-proxygen>
XML vilely stolen from samples and changed.
Any help? Thanks.
I'm rewriting build.xml file from Ant to Phing and everything goes fine with one exception.
I need to add new line at the end of each appended file but I can't find any alternative for fixlastline="true".
In Ant it was
<concat destfile="${libraryFilePrefix}.js" fixlastline="yes">
<!-- many filesets -->
</concat>
In Phing it's like
<append destfile="${libraryFilePrefix}.js">
<!-- many filesets -->
</append>
Is there any attribute that works like fixlastline or maybe I need to find another way to achieve this?
I believe, one of the approaches (and possibly the only one) is applying replaceregexp filter on each fileset. You only need to apply filterchain at the beginning and it will do the job for each fileset, like this:
<append destfile="${libraryFilePrefix}.js">
<filterchain>
<replaceregexp>
<regexp pattern="([^\n])$" replace="$1${line.separator}" ignoreCase="true"/>
</replaceregexp>
</filterchain>
<!-- many filesets -->
</append>
As of Phing 3.x the AppendTask is aware of the fixlastline attribute. Your Ant script provided is now working as expected
<project name="concat-supports-fixlastline" default="concat-fixed-lastline" basedir=".">
<target name="concat-fixed-lastline">
<concat destfile="${libraryFilePrefix}.js" fixlastline="yes">
<!-- many filesets -->
</concat>
</target>
</project>
I've recently been experimenting with an ANT script for setting up a small application (with various paths and other variables) using AntForm. AntForm has a file selector, but I would have to write something custom to validate the path (i.e., make sure it is the path to the thing that I asked the user for). I was wondering if anyone had experience with using using AntForm in this way. What I want is something like a Wizard page with a file selector, and when the user clicks "next" or when the file is selected some sort of a validation task is executed, and the wizard proceeds from there. The absolute best would be if I could gray out the "next" button or add an "invalid path" message, but that's getting a little complicated for what it seems that AntForm was designed for. Below is an example XML file to get started. Note that it expects AntForm.jar to be in the ./bin directory.
<?xml version="1.0"?>
<project name="My App Setup" default="getPath" basedir=".">
<property name="app.dir" value="${user.home}/appXYZ"/>
<path id="runtime.cp">
<pathelement location="bin/"/>
<fileset dir="lib" includes="antform.jar"/>
</path>
<taskdef name="antform" classname="com.sardak.antform.AntForm"
classpathref="runtime.cp"/>
<taskdef name="antmenu" classname="com.sardak.antform.AntMenu"
classpathref="runtime.cp"/>
<!-- test wizard behaviour, step 1 -->
<target name="getPath"
description="Check for App XYZ in path">
<antform title="Choose directory of app xyz"
lookAndFeel="com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
okMessage="Next"
nextTarget="wizard2"
>
<fileSelectionProperty
label="App XYZ Distribution"
property="app.dir"
directoryChooser="true" />
<!-- TODO: how to validate and choose where to go from this form? -->
</antform>
</target>
<!-- test wizard behaviour, step 1 -->
<target name="wizard2"
description="continue setup">
<antform title="did we validate?"
lookAndFeel="com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
okMessage="Finish"
previousTarget="getPath"
>
<label>Did we validate the path before we got here?</label>
</antform>
</target>
</project>
I need to retrieve some values from an HTML file. I need to use Ant so I can use these values in other parts of my script.
Can this even be achieved in Ant?
As stated in the other answers you can't do this in "pure" XML. You need to embed a programming language. My personal favourite is Groovy, it's integration with ANT is excellent.
Here's a sample which retrieves the logo URL, from the groovy homepage:
parse:
print:
[echo]
[echo] Logo URL: http://groovy.codehaus.org/images/groovy-logo-medium.png
[echo]
build.xml
Build uses the ivy plug-in to retrieve all 3rd party dependencies.
<project name="demo" default="print" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="resolve">
<ivy:resolve/>
<ivy:cachepath pathid="build.path" conf="build"/>
</target>
<target name="parse" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<groovy>
import org.htmlcleaner.*
def address = 'http://groovy.codehaus.org/'
// Clean any messy HTML
def cleaner = new HtmlCleaner()
def node = cleaner.clean(address.toURL())
// Convert from HTML to XML
def props = cleaner.getProperties()
def serializer = new SimpleXmlSerializer(props)
def xml = serializer.getXmlAsString(node)
// Parse the XML into a document we can work with
def page = new XmlSlurper(false,false).parseText(xml)
// Retrieve the logo URL
properties["logo"] = page.body.div[0].div[1].div[0].div[0].div[0].img.#src
</groovy>
</target>
<target name="print" depends="parse">
<echo>
Logo URL: ${logo}
</echo>
</target>
</project>
The parsing logic is pure groovy programming. I love the way you can easily walk the page's DOM tree:
// Retrieve the logo URL
properties["logo"] = page.body.div[0].div[1].div[0].div[0].div[0].img.#src
ivy.xml
Ivy is similar to Maven. It manages your dependencies on 3rd party software. Here it's being used to pull down groovy and the HTMLCleaner library the groovy logic is using:
<ivy-module version="2.0">
<info organisation="org.myspotontheweb" module="demo"/>
<configurations defaultconfmapping="build->default">
<conf name="build" description="ANT tasks"/>
</configurations>
<dependencies>
<dependency org="org.codehaus.groovy" name="groovy-all" rev="1.8.2"/>
<dependency org="net.sourceforge.htmlcleaner" name="htmlcleaner" rev="2.2"/>
</dependencies>
</ivy-module>
How to install ivy
Ivy is a standard ANT plugin. Download it's jar and place it in one of the following directories:
$HOME/.ant/lib
$ANT_HOME/lib
I don't know why the ANT project doesn't ship with ivy.
Yes this is very possible.
Note that in order to use this solution you will need to set your JAVA_HOME variable to JRE 1.6 or later.
<project name="extractElement" default="test">
<!--Extract element from html file-->
<scriptdef name="findelement" language="javascript">
<attribute name="tag" />
<attribute name="file" />
<attribute name="property" />
<![CDATA[
var tag = attributes.get("tag");
var file = attributes.get("file");
var regex = "<" + tag + "[^>]*>(.*?)</" + tag + ">";
var patt = new RegExp(regex,"g");
project.setProperty(attributes.get("property"), patt.exec(file));
]]>
</scriptdef>
<!--Only available target...-->
<target name="test">
<!--Load html file into property-->
<loadfile srcFile="D:\Tools\CruiseControl\Build\artifacts\RECO\20110831100942\RECO_merged_report.html" property="html.file"/>
<!--Find element with specific tag and save it to property element-->
<findelement tag="title" file="${html.file}" property="element"/>
<echo message="File : ${html.file}"/>
<echo message="Title : ${element}"/>
</target>
</project>
Output : [echo] Title : <title>Test Report</title>,Test Report
As I don't know what exactly variables you were looking for this particular solution will find all elements that you specify in the tag attribute. Of course you could modify the regex to suit your own specific needs.
Also this is pure build.xml ant with no external dependencies whatsoever.
Sure, but you have to write your own task for it. Visit http://ant.apache.org/manual/develop.html#writingowntask for more information about writing own tasks for Ant. In your Ant task you may parse your HTML file as needed.
I claim, that it is not directly possible with "pure" XML (build.xml) to achieve what you want.
Take a look at the (http://ant.apache.org/manual/Tasks/xmlproperty.html) task and see if it'll work for you. It's pretty straight forward:
<xmlProperty file="${html.file}"
prefix="html."/>
After all, HTML is just a subset of XML. I've used it before to do this very task. No need to write your own task or script.