<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: build code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 22:02:19 GMT</pubDate>
    <description>DZone Snippets: build code</description>
    <item>
      <title>'ant' build file for HelloWorldServlet and JettyLauncher</title>
      <link>http://snippets.dzone.com/posts/show/4096</link>
      <description>A pretty straightforward 'ant' build file. You will need to edit the jetty.home property to indicate where you installed Jetty.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;project basedir="." default="compile" name="hello-servlet"&gt;&lt;br /&gt;  &lt;property name="build.dir"	location="classes" /&gt;&lt;br /&gt;  &lt;property name="src.dir"	location="src/main/java" /&gt;&lt;br /&gt;  &lt;property name="jetty.home"	location="/home/mrw/projects/jetty-6.1.3" /&gt;&lt;br /&gt;  &lt;property name="jetty.lib"	location="${jetty.home}/lib" /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;path id="jetty.lib.path"&gt;&lt;br /&gt;    &lt;pathelement path="${jetty.lib}/jetty-6.1.3.jar" /&gt;&lt;br /&gt;    &lt;pathelement path="${jetty.lib}/jetty-util-6.1.3.jar" /&gt;&lt;br /&gt;    &lt;pathelement path="${jetty.lib}/servlet-api-2.5-6.1.3.jar" /&gt;&lt;br /&gt;  &lt;/path&gt;&lt;br /&gt;&lt;br /&gt;  &lt;target name="compile" description="Compile the project"&gt;&lt;br /&gt;    &lt;mkdir dir="${build.dir}" /&gt;&lt;br /&gt;    &lt;javac debug="true" destdir="${build.dir}" srcdir="${src.dir}"&lt;br /&gt;	classpathref="jetty.lib.path"&gt;&lt;br /&gt;      &lt;compilerarg value="-Xlint:unchecked" /&gt;&lt;br /&gt;      &lt;compilerarg value="-Xlint:deprecation" /&gt;&lt;br /&gt;    &lt;/javac&gt;&lt;br /&gt;  &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;  &lt;target name="all"  depends="clean,compile"&lt;br /&gt;      description="Recompile from scratch"/&gt;&lt;br /&gt;&lt;br /&gt;  &lt;target name="server" depends="compile" description="Launch the server"&gt;&lt;br /&gt;    &lt;java classname="com.babblemind.JettyLauncher" fork="true"&lt;br /&gt;	classpathref="jetty.lib.path"&gt;&lt;br /&gt;      &lt;classpath&gt;&lt;br /&gt;	&lt;pathelement path="${build.dir}" /&gt;&lt;br /&gt;      &lt;/classpath&gt;&lt;br /&gt;    &lt;/java&gt;&lt;br /&gt;  &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;  &lt;target name="clean" description="Delete all files created by compile"&gt;&lt;br /&gt;    &lt;delete dir="${build.dir}" /&gt;&lt;br /&gt;    &lt;delete dir="docs/api" /&gt;&lt;br /&gt;  &lt;/target&gt;&lt;br /&gt;&lt;/project&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 02 Jun 2007 11:15:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4096</guid>
      <author>mikewilsonuk (Mike Wilson)</author>
    </item>
    <item>
      <title>Automated GNU Makefile</title>
      <link>http://snippets.dzone.com/posts/show/3948</link>
      <description>A simple automated GNU Makefile to build and link c/c++/asm projects. All the variables that need to be tweaked are located at the begining:&lt;br /&gt;    PROGNAME: the name of the executable to be built&lt;br /&gt;    CC: the C compiler&lt;br /&gt;    CPP: the C++ compiler&lt;br /&gt;    ASM: the assambler&lt;br /&gt;    LD: the linker&lt;br /&gt;&lt;br /&gt;This searches for all *.c, *.cpp and *.s files and compiles them into objects. It then links all the files into a single executable.&lt;br /&gt;&lt;br /&gt;The strip rule is used to strip all unwanted symbols from the resulting executable. This usually results in a significant (think 40%) size optimisation.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$(VERBOSE).SILENT:&lt;br /&gt;&lt;br /&gt;PROGNAME = prog&lt;br /&gt;&lt;br /&gt;CC = gcc&lt;br /&gt;CC += -c&lt;br /&gt;CPP = g++&lt;br /&gt;CPP += -c&lt;br /&gt;ASM = nasm&lt;br /&gt;ASM += -f elf -d ELF_TYPE&lt;br /&gt;LD = g++&lt;br /&gt;&lt;br /&gt;OBJFILES = $(patsubst %.c,%.o,$(wildcard *.c))&lt;br /&gt;OBJFILES += $(patsubst %.s,%.o,$(wildcard *.s))&lt;br /&gt;OBJFILES += $(patsubst %.cpp,%.o,$(wildcard *.cpp))&lt;br /&gt;&lt;br /&gt;all: $(PROGNAME)&lt;br /&gt;&lt;br /&gt;clean:&lt;br /&gt;	@echo "Cleaning object files"&lt;br /&gt;	@echo "    rm -f     *.o"&lt;br /&gt;	rm -f *.o&lt;br /&gt;	@echo "Cleaning backups"&lt;br /&gt;	@echo "    rm -f     *~"&lt;br /&gt;	rm -f *~&lt;br /&gt;	@echo "Removing programme"&lt;br /&gt;	@echo "    rm -f     "$(PROGNAME)&lt;br /&gt;	rm -f $(PROGNAME)&lt;br /&gt;&lt;br /&gt;%.o: %.s&lt;br /&gt;	@echo "Assambling "$@&lt;br /&gt;	@echo "    ASM       "$&lt;&lt;br /&gt;	$(ASM) $&lt;&lt;br /&gt;&lt;br /&gt;%.o: %.c&lt;br /&gt;	@echo "Compiling "$@&lt;br /&gt;	@echo "    CC        "$&lt;&lt;br /&gt;	$(CC) $&lt;&lt;br /&gt;&lt;br /&gt;%.o: %.cpp&lt;br /&gt;	@echo "Compiling "$@&lt;br /&gt;	@echo "    CPP       "$&lt;&lt;br /&gt;	$(CPP) $&lt;&lt;br /&gt;&lt;br /&gt;$(PROGNAME): $(OBJFILES)&lt;br /&gt;	@echo "Linking "$@&lt;br /&gt;	@echo "    LD        -o "$(PROGNAME)"        "$(OBJFILES)&lt;br /&gt;	$(LD) -o $(PROGNAME) $(OBJFILES)&lt;br /&gt;&lt;br /&gt;strip: $(PROGNAME)&lt;br /&gt;	@echo "Stripping "$(PROGNAME)&lt;br /&gt;	echo -n "Size of "$(PROGNAME)" before strip is "&lt;br /&gt;	ls -sh $(PROGNAME) | cut -d' ' -f1&lt;br /&gt;	@echo "    strip     "$(PROGNAME)&lt;br /&gt;	strip $(PROGNAME)&lt;br /&gt;	echo -n "Size of "$(PROGNAME)" after strip is "&lt;br /&gt;	ls -sh $(PROGNAME) | cut -d' ' -f1&lt;br /&gt;&lt;br /&gt;nothing:&lt;br /&gt;	@echo "Nothing to do; quitting  :("&lt;br /&gt;	@echo "HINT: Try make all"&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 02 May 2007 17:43:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3948</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
    <item>
      <title>Basic ant script with vim &amp; jikes</title>
      <link>http://snippets.dzone.com/posts/show/2077</link>
      <description>Apache ant build XML. This will use jikes in place of javac. Any compiler error output is formatted so that vim can parse it.&lt;br /&gt;&lt;br /&gt;ant is a modern alternative to make. The build script is an XML file. It works particularly well with java. Download it for free from the &lt;a href="http://ant.apache.org/"&gt;Apache ant&lt;/a&gt; site. Most people find ant a lot nicer to live with than make.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;project name="Hello" default="compile" basedir="."&gt;&lt;br /&gt;  &lt;property name="name" value="Hello"/&gt;&lt;br /&gt;  &lt;property name="version" value="1.0"/&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- Project directories.&lt;br /&gt;  --&gt;&lt;br /&gt;&lt;br /&gt;  &lt;property name="build" value="build"/&gt;&lt;br /&gt;  &lt;property name="dist" value="dist"/&gt;&lt;br /&gt;  &lt;property name="src" value="src"/&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- Compiler directives.&lt;br /&gt;  --&gt;&lt;br /&gt;&lt;br /&gt;  &lt;property name="optimize" value="off"/&gt;&lt;br /&gt;  &lt;property name="deprecation" value="on"/&gt;&lt;br /&gt;  &lt;property name="debug" value="on"/&gt;&lt;br /&gt;&lt;br /&gt;  &lt;property name="build.compiler" value="jikes"/&gt;&lt;br /&gt;  &lt;property name="build.compiler.emacs" value="true"/&gt;&lt;br /&gt;&lt;br /&gt;  &lt;target name="init"&gt;&lt;br /&gt;    &lt;tstamp/&gt;&lt;br /&gt;    &lt;mkdir dir="${build}"/&gt;&lt;br /&gt;  &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- Compile all the .java files from the source directory into&lt;br /&gt;       the build directory.&lt;br /&gt;  --&gt;&lt;br /&gt;&lt;br /&gt;  &lt;target name="compile" depends="init"&gt;&lt;br /&gt;    &lt;javac srcdir="${src}" destdir="${build}" includes="**/*.java"&lt;br /&gt;      debug="${debug}" deprecation="${deprecation}" optimize="${optimize}"&gt;&lt;br /&gt;    &lt;/javac&gt;&lt;br /&gt;  &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;  &lt;target name="clean" depends="init"&gt;&lt;br /&gt;    &lt;delete dir="${build}"/&gt;&lt;br /&gt;    &lt;delete dir="${dist}"/&gt;&lt;br /&gt;  &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;  &lt;target name="test" depends="compile"&gt;&lt;br /&gt;    &lt;java classname="HelloWorld" fork="yes"&gt;&lt;br /&gt;      &lt;classpath&gt;&lt;br /&gt;        &lt;pathelement location="${build}"/&gt;&lt;br /&gt;      &lt;/classpath&gt;&lt;br /&gt;    &lt;/java&gt;&lt;br /&gt;  &lt;/target&gt;&lt;br /&gt;&lt;/project&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 19 May 2006 19:39:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2077</guid>
      <author>mikewilsonuk (Mike Wilson)</author>
    </item>
    <item>
      <title>Ant 101</title>
      <link>http://snippets.dzone.com/posts/show/1600</link>
      <description>// Ah Ant. How I love thee, how much better a build tool&lt;br /&gt;// than my ex build tool Make.&lt;br /&gt;//&lt;br /&gt;// This is my current starting build.xml Ant script for any&lt;br /&gt;// Java project. It specifies my usual directories, it will&lt;br /&gt;// build source code, make a Jar, build a War, clean up build&lt;br /&gt;// products, create Javadoc, and even run unit tests.&lt;br /&gt;//&lt;br /&gt;// Notice that I use the JReleaseInfo library to automatically&lt;br /&gt;// generate a Java class that contains version numbers, build&lt;br /&gt;// numbers, etc. Be sure to put the Jar from that library in&lt;br /&gt;// the library directory to get that feature:&lt;br /&gt;// http://jreleaseinfo.sourceforge.net/&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;project name="New Project" basedir="." default="all"&gt;&lt;br /&gt;    &lt;target name="init"&gt;&lt;br /&gt;        &lt;property name="appName" value="newProject"/&gt;&lt;br /&gt;    &lt;br /&gt;        &lt;property name="buildDir" value="${basedir}/build"/&gt;&lt;br /&gt;        &lt;property name="libDir" value="${basedir}/lib"/&gt;&lt;br /&gt;        &lt;property name="javaSourceDir" value="${basedir}/src"/&gt;&lt;br /&gt;        &lt;property name="testDir" value="${basedir}/test"/&gt;&lt;br /&gt;        &lt;property name="webSourceDir" value="${basedir}/web"/&gt;&lt;br /&gt;        &lt;property name="etcDir" value="${basedir}/etc"/&gt;&lt;br /&gt;        &lt;property name="tempDir" value="${basedir}/tmp"/&gt;&lt;br /&gt;        &lt;property name="classDir" value="${buildDir}/classes"/&gt;&lt;br /&gt;&lt;br /&gt;        &lt;!-- This may get overridden when we are called from Anthill. --&gt;&lt;br /&gt;        &lt;property name="version" value="Local Build"/&gt;&lt;br /&gt;        &lt;property name="deployDir" value="${buildDir}"/&gt;&lt;br /&gt;&lt;br /&gt;        &lt;property name="distDir" value="${deployDir}/dist"/&gt;&lt;br /&gt;        &lt;property name="junitDir" value="${deployDir}/JUnit"/&gt;&lt;br /&gt;        &lt;property name="javadocDir" value="${deployDir}/apidoc"/&gt;&lt;br /&gt;&lt;br /&gt;        &lt;!-- Create the directories where we put all the build products. --&gt;    &lt;br /&gt;        &lt;mkdir dir="${buildDir}"/&gt;&lt;br /&gt;        &lt;mkdir dir="${classDir}"/&gt;&lt;br /&gt;        &lt;mkdir dir="${distDir}"/&gt;&lt;br /&gt;        &lt;mkdir dir="${junitDir}"/&gt;&lt;br /&gt;        &lt;mkdir dir="${javadocDir}"/&gt;&lt;br /&gt;&lt;br /&gt;        &lt;path id="compileClasspath"&gt;&lt;br /&gt;            &lt;fileset dir="${libDir}"/&gt;&lt;br /&gt;        &lt;/path&gt;&lt;br /&gt;&lt;br /&gt;        &lt;!-- Make available build info in such a way that we can display it to the user. --&gt;&lt;br /&gt;        &lt;taskdef name="jreleaseinfo" classname="ch.oscg.jreleaseinfo.anttask.JReleaseInfoAntTask"&gt;&lt;br /&gt;            &lt;classpath refid="compileClasspath"/&gt;&lt;br /&gt;        &lt;/taskdef&gt;&lt;br /&gt;&lt;br /&gt;        &lt;jreleaseinfo className="MyReleaseInfo" packageName="com.johnmunsch.${appName}"&lt;br /&gt;                targetDir="${javaSourceDir}" project="${appName}" version="${version}" &lt;br /&gt;                buildNumFile="buildnum.properties" buildNumProperty="buildnum"&gt;&lt;br /&gt;            &lt;parameter name="VersionNum" type="int" value="1" /&gt;&lt;br /&gt;            &lt;parameter name="RevisionNum" type="Integer" value="0" /&gt;&lt;br /&gt;        &lt;/jreleaseinfo&gt;&lt;br /&gt;    &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;    &lt;target name="compile" depends="init"&gt;&lt;br /&gt;        &lt;javac srcdir="${javaSourceDir}" destdir="${classDir}" debug="true" deprecation="true"&gt;&lt;br /&gt;            &lt;classpath refid="compileClasspath"/&gt;&lt;br /&gt;        &lt;/javac&gt;&lt;br /&gt;&lt;br /&gt;        &lt;!-- Copy files needed to run the software to destinations in the &lt;br /&gt;         build directory. I do this because I usually pull all binary files like&lt;br /&gt;         this from inside the Jar files that make up my application rather than&lt;br /&gt;         having them loose. So they need to be copied to the class dir so they&lt;br /&gt;         get included in the Jar file for the application. --&gt;&lt;br /&gt;        &lt;copy todir="${classDir}" &gt;&lt;br /&gt;            &lt;fileset dir="${javaSourceDir}"&gt;&lt;br /&gt;                &lt;include name="**/*.gif"/&gt;&lt;br /&gt;                &lt;include name="**/*.jpg"/&gt;&lt;br /&gt;                &lt;include name="**/*.png"/&gt;&lt;br /&gt;                &lt;include name="**/*.wav"/&gt;&lt;br /&gt;                &lt;include name="**/*.dtd"/&gt;&lt;br /&gt;                &lt;include name="**/*.properties"/&gt;&lt;br /&gt;            &lt;/fileset&gt;&lt;br /&gt;        &lt;/copy&gt;&lt;br /&gt;    &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;    &lt;target name="jar" depends="init,compile"&gt;&lt;br /&gt;        &lt;jar jarfile="${distDir}/${appName}.jar" compress="true" &lt;br /&gt;            basedir="${classDir}"/&gt;&lt;br /&gt;    &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;    &lt;target name="war" depends="jar"&gt;&lt;br /&gt;        &lt;war destfile="${distDir}/${appName}.war" webxml="${etcDir}/WEB-INF/web.xml"&gt;&lt;br /&gt;            &lt;fileset dir="web"/&gt;&lt;br /&gt;            &lt;lib dir="${libDir}"&gt;&lt;br /&gt;                &lt;include name="jstl.jar"/&gt;&lt;br /&gt;                &lt;include name="standard.jar"/&gt;&lt;br /&gt;            &lt;/lib&gt;&lt;br /&gt;            &lt;lib dir="${libDir}"&gt;&lt;br /&gt;                &lt;include name="*.jar"/&gt;&lt;br /&gt;            &lt;/lib&gt;&lt;br /&gt;            &lt;lib dir="${distDir}"&gt;&lt;br /&gt;                &lt;include name="${appName}.jar"/&gt;&lt;br /&gt;            &lt;/lib&gt;&lt;br /&gt;        &lt;/war&gt;&lt;br /&gt;    &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;    &lt;target name="all" depends="war" description="Build everything."&gt;&lt;br /&gt;        &lt;echo message="Application built."/&gt;&lt;br /&gt;    &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;    &lt;target name="javadoc" depends="init" description="Javadoc for the code."&gt;&lt;br /&gt;        &lt;javadoc packagenames="*" sourcepath="${javaSourceDir}" &lt;br /&gt;	        destdir="${javadocDir}"/&gt;&lt;br /&gt;    &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;    &lt;target name="clean" depends="init" description="Clean all build products."&gt;&lt;br /&gt;        &lt;delete dir="${tempDir}"/&gt;&lt;br /&gt;        &lt;delete dir="${javadocDir}"/&gt;&lt;br /&gt;        &lt;delete dir="${junitDir}"/&gt;&lt;br /&gt;        &lt;delete dir="${distDir}"/&gt;&lt;br /&gt;        &lt;delete dir="${classDir}"/&gt;&lt;br /&gt;        &lt;delete dir="${buildDir}"/&gt;&lt;br /&gt;    &lt;/target&gt;&lt;br /&gt;&lt;br /&gt;    &lt;target name="junit" depends="jar" description="Performs unit tests."&gt;&lt;br /&gt;        &lt;javac srcdir="test" destdir="${classDir}" debug="true" deprecation="true"&gt;&lt;br /&gt;            &lt;classpath refid="compileClasspath"/&gt;&lt;br /&gt;        &lt;/javac&gt;&lt;br /&gt;&lt;br /&gt;        &lt;mkdir dir="${tempDir}"/&gt;&lt;br /&gt;&lt;br /&gt;        &lt;junit failureproperty="junit.failed"&gt;&lt;br /&gt;            &lt;formatter type="xml"/&gt;&lt;br /&gt;            &lt;batchtest todir="${tempDir}"&gt;&lt;br /&gt;                &lt;fileset dir="${classDir}"&gt;&lt;br /&gt;                   &lt;include name="**/*Test.class"/&gt;&lt;br /&gt;                   &lt;include name="**/Test*.class"/&gt;&lt;br /&gt;                &lt;/fileset&gt;&lt;br /&gt;            &lt;/batchtest&gt;&lt;br /&gt;            &lt;classpath&gt;&lt;br /&gt;                &lt;path refid="compileClasspath"/&gt;&lt;br /&gt;                &lt;pathelement location="${classDir}"/&gt;&lt;br /&gt;            &lt;/classpath&gt;&lt;br /&gt;        &lt;/junit&gt;&lt;br /&gt;&lt;br /&gt;        &lt;mkdir dir="${buildDir}/JUnit"/&gt;&lt;br /&gt;&lt;br /&gt;        &lt;junitreport tofile="TESTS-TestSuites.xml" todir="${tempDir}"&gt;&lt;br /&gt;            &lt;fileset dir="${tempDir}"&gt;&lt;br /&gt;                &lt;include name="TEST-*.xml"/&gt;&lt;br /&gt;            &lt;/fileset&gt;&lt;br /&gt;            &lt;report todir="${junitDir}"/&gt;&lt;br /&gt;        &lt;/junitreport&gt;&lt;br /&gt;  	&lt;br /&gt;        &lt;fail message="JUnit test failure." if="junit.failed"/&gt;  	&lt;br /&gt;    &lt;/target&gt;&lt;br /&gt;&lt;/project&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 28 Feb 2006 20:31:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1600</guid>
      <author>JohnMunsch (John Munsch)</author>
    </item>
  </channel>
</rss>
