Tools

Any tools can be used to develop modules for M2M2. Your selection depends upon the type of functionality that you intent to create. At a minimum, a text editor will be needed, and if you are implementing Java code you will need a Java compiler. (The compiler is included with the JDK.) The M2M2 core is developed for Java 6, but modules written for previous versions of Java will also work.

It is recommended, however, that you take advantage of the very powerful tools that are available, some of which are free. For example, the M2M2 core is developed using Eclipse. Source code is managed using Subversion. And to create module distributions ANT is used. The ANT script below is what is used in nearly every M2M2 related project by Serotonin Software. You are free to copy, modify, use, and redistribute it as required. You may need to change the "coreHome" property to suit your environment.

<?xml version="1.0"?>

<project name="M2M2 - My project name" basedir="." default="deploy">
    <property file="module.properties" />
    <property name="fullName" value="m2m2-${name}-${version}" />
    <property name="coreHome" value="../Core"/>

    <path id="master-classpath">
        <pathelement path="${coreHome}/bin" />
        <fileset dir="${coreHome}/lib">
            <include name="*.jar" />
        </fileset>
        <fileset dir="lib">
            <include name="*.jar" />
        </fileset>
        <pathelement path="target" />
    </path>

    <target name="clean" description="Clean the target area">
        <delete dir="target" />
    </target>

    <target name="compile" description="Compile main source tree java files">
        <mkdir dir="target" />
        <javac destdir="target" target="1.6" source="1.6" debug="true" 
                debuglevel="lines,vars,source" deprecation="false" optimize="false" failonerror="true">
            <src path="src" />
            <classpath refid="master-classpath" />
        </javac>
    </target>

    <target name="jar" depends="clean,compile" description="Create a jar file of the compiled classes">
        <delete file="${fullName}.jar" />
        <delete file="target/MANIFEST.MF" />
        <tstamp>
            <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
        </tstamp>

        <manifest file="target/MANIFEST.MF">
            <attribute name="Built-By" value="Serotonin Software Inc., Markham, Ontario" />
            <attribute name="Build-Date" value="${TODAY}" />
        </manifest>

        <mkdir dir="target/lib" />
        <jar destfile="target/lib/${fullName}.jar" manifest="target/MANIFEST.MF">
            <fileset dir="target">
                <include name="**/*.class" />
                <exclude name="MANIFEST.MF" />
            </fileset>
        </jar>
    </target>

    <target name="zip" depends="jar" description="Create a zip file of the module">
        <delete file="${fullName}.zip" />
        <zip destfile="${fullName}.zip">
            <fileset dir="">
                <include name="module.properties" />
                <include name="RELEASE-NOTES" />
            </fileset>
            <fileset dir="target/">
                <include name="lib/${fullName}.jar" />
            </fileset>
            <fileset dir="">
                <include name="lib/**/*.jar" />
            </fileset>
            <fileset dir="">
                <include name="web/**/*" />
            </fileset>
            <fileset dir="">
                <include name="classes/**/*" />
            </fileset>
        </zip>
    </target>
    
    <target name="deploy" depends="zip" description="Copy the zip to the M2M2 app">
        <copy todir="${coreHome}/web/modules" preservelastmodified="true">
            <fileset file="${fullName}.zip"/>
        </copy>
    </target>
</project>