Ant Tips

From EggeWiki
Revision as of 03:14, 23 September 2007 by Egge (talk | contribs)

Use ant to create a properties java file which can be compiled

<geshi lang="xml">

   <target name="build-properties">
      <copy todir="src">
           <fileset dir="src">
               <include name="**/*.hava"/>
           </fileset>
          <globmapper from="*.hava" to="*.java"/>
          <filterset>
              <filtersfile file="src/resources/messages_en_AU_company.properties" />
          </filterset>
       </copy>
   </target>

</geshi>


Ant is great, but the XML gets to suck after a while.

  • If I knew then what I knew now, I would have tried using a real scripting language, such as ~JavaScript via the Rhino component or Python via JPython, with bindings to Java objects which implemented the functionality expressed in todays tasks. Then, there would be a first class way to express logic and we wouldn't be stuck with XML as a format that is too bulky for the way that people really want to use the tool.

Ant is giving you this error when using a fileset:

java.lang.NoClassDefFoundError: org/apache/oro/text/regex/MalformedPatternException

You need to download the Jararta ORO libarary. Install the jar in you ant/lib directory.

! You get some stack trace like this:

 java.lang.NumberFormatException: multiple points
  at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1067)
  at java.lang.Double.parseDouble(Double.java:220)
  at java.text.DigitList.getDouble(DigitList.java:127)
  at java.text.DecimalFormat.parse(DecimalFormat.java:1070)
  at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1705)
  at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1156)
  at java.text.DateFormat.parse(DateFormat.java:333)

This might be caused by your ~SimpleDateFormat object being used concurrently. The spec says you can't:

  Date formats are not synchronized. It is recommended to create separate format instances for
  each thread. If multiple threads access a format concurrently, it must be synchronized externally.

How to require an environment variable in an Ant file

<property environment="env"/><BR>
<fail message="Provide MY_VAR" unless="env.MY_VAR"/>

Remove Ant Configuration Dialog from Eclipse

In Eclipse 3.0 you can launch Ant tasks. This is a great feature. If you don't want to run with the default settings, you can open the configuration settings and add environment variables and add flags. Sometimes I like to add a "-verbose" flag. The problem is after this you are stuck with the configuration dialog popping up each time you launch a target. To stop this, you must delete files in your Eclipse workspace settings. My files are in:

H:\eclipseworkspace\.metadata\.plugins\org.eclipse.debug.core\.launches

Then restart Eclipse, and you can now run Ant tasks simply by double clicking on them.