Archive for the 'ant' Category

03
Sep
11

run a class from a jar using ant


Here’s how you can run any class from a jar file, using ant:


<java classname="my.class">
  <classpath>
     <pathelement location="my.jar"/>
  </classpath>
</java>

03
Sep
11

increase ant memory


Recently, I had to increase the memory ant was using. This is what I used:


set ANT_OPTS=-Xmx256m

10
Mar
10

using ruby from ant


An example on how you could use a fileset from a ruby script task:


<script language="ruby" classpathref="jruby_classpath">
	task = $project.createDataType("fileset")
	task.case_sensitive = false
	task.setDir java.io.File.new($basedir)
	task.setIncludes("**/*.*")
	task.setExcludes("**/*test*/**")
	scanner = task.getDirectoryScanner($project)
	scanner.getIncludedFiles.each {|f| puts f}
</script>

This snippet will include every file in the basedir, except those containing the string test.

15
Oct
09

getting a basename from a path using ant


If you have a path written in a file, and you’d like to get a basename from it, like in the following example:

/this/is/my/path.txt

after you run this target, you will have only path.txt. Here’s the code that makes that possible:


<target name="rgx" description="basename equivalent">
	<replaceregexp file="a.txt" match="(.*/)|(.*\\)" replace="" byline="true"/>
</target>

27
Aug
09

replacing a windows path with a unix one using ant


If for some reason ant interprets your backslashes and you need slashes to make your thing work, here’s a snippet that will convert your windows style path to a unix style one :

  1. <target name="replace-path-example">
  2.   <property name="WIN_PATH" refid="some.path"/>
  3.   <echo message="${WIN_PATH}" file="temp.file"/>
  4.   <replace file="temp.file" token="\" value="/"/>
  5.   <loadfile srcfile="temp.file" property="UNIX_PATH"/>
  6.   <echo message="path is ${UNIX_PATH}"/>
  7.   <delete file="temp.file"/>
  8. </target>

22
Jul
09

some ant tips


Here are some tips I can offer you which will most certainly make your life easier :

  1. use the basedir variable instead of ., ant’s consideration of “.” is very strange
  2. use the ANT_OPTS environment variable to set the java.library.path

If I had known these tips, I would have saved several hours of work.




Blog Stats

  • 216,787 hits