Java Preprocessor Using Eclipse Part 8 PDF Print E-mail
Written by Administrator   
Monday, 04 January 2010 05:18

Java Preprocessor Using Eclipse Part 8

<-- Prev Page

 

 In the xml build file, we now have two sections with Ant task = "preprocess".   The first sets a variable called 'pro' to false and processes the source before storing it in /tmp/Hello/lite.   Then it sets 'pro' to true, and processes the source code while copying it to /tmp/Hello/pro.

 


    <target name="splitsource"  description="preprocessor">
        <preprocess indir="${src}" outdir="${src_lite}" out="replace">
            <var name="pro" value="false"/>
            <filetype commentend="*/" commentbegin="/*" extensions="java"/>
        </preprocess>
        <preprocess indir="${src}" outdir="${src_pro}" out="replace">
            <var name="pro" value="true"/>
            <filetype commentend="*/" commentbegin="/*" extensions="java"/>
        </preprocess>
    </target>


 

 So what we need to do is modify the Hello.java source doe so the preprocessor will have something to do besides copy files.

in Hello.java, replace the Main method with this one:


 

    public static void main(String[] args)
    {
        /* $if pro$
            System.out.println("Welcome to the PRO version of this wonderful software.  :) ");
         $else
            System.out.println("This is the lousy, crippled, and worthless version");
         $endif$ */
    }


  For more information about how prebop processes text, please see this document.

   There should be a Hello.class in the Pro directory which reports itself as pro.   

    Make another debug target by clicking on the run as arrow and then select Debug Configurations.   Clone the original and rename the clone debug configuration to 'Debug - Pro'.  Then go to the classpath settings and the 'Advanced' button to add the fold bin/pro to the classpath.

    Note that we could also add a build step for creating the jar files also.   To do this we would add another target to the prebopBuild.xml file:

	<!--Creates the deployable jar file  -->
<target name="jar" depends="compile">
<jar destfile="${output_lite}\Hello.jar" basedir="${build_lite}">
<manifest>
<attribute name="Main-Class" value="myPackage.Hello" />
</manifest>
</jar>
<jar destfile="${output_pro}\Hello.jar" basedir="${build_pro}">
<manifest>
<attribute name="Main-Class" value="myPackage.Hello" />
</manifest>
</jar>
</target>

NOTE:  The above assumes you have already added the lines to the xml script to create the output_lite and output_pro folders, just like we did for the source folders and the build folders.

Thank you for reading this tutorial.  I hope you found it useful.

 

The End

 

Last Updated on Monday, 04 January 2010 13:02
 

Sponsored Links

Bold Inventions, Powered by Joomla!; Joomla templates by SG web hosting