Cimande:Bundle Your Project

From BlueOxygen Wiki

Jump to: navigation, search

Cimande allows you to bundle your project become a JAR, so we can distribute easily.

Inside the JAR file there are a compiled version of Action, Template and a Struts' XML

You need to add build folder inside your project (outside /src).

Inside the build folder there are:

  1. build.xml, an ant script to compile
  2. build.properties
  3. db.properties, db setting

the build.xml is work smiliar with the build.xml bundled inside Cimande SDK, but there are several setting to map the project with Cimande SDK, and do a jar deployment.

Several pending setting are under development, such as dbunit integration, which we are still seeking the tasks to make this.

Contents

[edit] building a Bead or create your own SDK

to create a jar (we call it bead, a cimande based module), just execute the create-jar in your build.xml

ant create-jar

to create your own SDK, you can execute create-sdk-bundle, so your project will become another Cimande SDK.

ant create-sdk-bundle


[edit] build.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
 
<!-- Build file for BlueOxygen  -->
 
<project name="komodo-jeni" default="war" basedir="..">
 
    <!-- Give user a chance to override without editing this file 
         (and without typing -D each time they invoke a target) -->    
 
	   <property file="${basedir}/build/build.properties" />
		<property file="${basedir}/build/db.properties" />
 
    <!-- Generic project properties -->
 
    <property name="project.fullname" value="Komodo JENI Project"/>
    <property name="project.name" value="komodo-jeni"/>
 
    <property name="project.version" value="1.0"/>      
 
    <!-- Directory settings -->
    <property name="src.dir" value="${basedir}/src"/>
    <property name="src.java.dir" value="${src.dir}/java"/> 
	<property name="src.view.dir" value="${src.dir}/template/view"/>
    <property name="src.config.dir"   location="${cimande.src}/src/config"/>
 
    <property name="build.dir" value="${basedir}"/>
	<!-- 
    <property name="build.dest.dir" value="${build.dir}/classes"/>

	-->
 
 
	<property name="build.dest.generated.dir" value="${basedir}/generated"/>
 
	<property name="build.dest.blank.dir" value="${build.dest.generated.dir}/blank"/>
	<property name="build.dest.bundle.dir" value="${build.dest.generated.dir}/bundle"/>		
 
    <property name="build.dest.jar.dir" value="${basedir}/generated/bundle"/>
	<property name="build.dest.dir" value="${build.dest.generated.dir}/classes"/>
	<property name="build.dest.view.dir" value="${build.dest.generated.dir}/classes/view"/>
 
    <property name="lib.dir" value="${cimande.src}/WebContent/WEB-INF/lib"/>   
    <property name="docs.dir" value="${build.dest.generated.dir}/docs"/>
    <property name="javadocs.destdir" value="${docs.dir}/api"/>
    <property name="release.dir" value="${project.name}-${project.version}/"/>    
    <property name="install.war" value="${build.dir}/webapp"/>
    <property name="locale.default" value="en"/>
 
    <!-- Miscellaneous settings -->
 
    <property name="locale.default" value="en"/>
    <property name="debug" value="on"/>
    <property name="optimize" value="on"/>
    <property name="deprecation" value="off"/>  
 
    <!-- Anakia doc settings -->
    <property name="docs.dest" value="docs"/>
    <property name="docs.src" value="xdocs"/>  
 
    <!-- =================================================================== -->
    <!-- Builds Classpath                                                    -->
    <!-- =================================================================== -->
    <path id="classpath">
        <!-- include all jar from WebContent library folder -->
    	<fileset dir="${lib.dir}">
            <include name="*.jar"/>
        </fileset>
		<!-- adding build library to classpath -->
        <fileset dir="${cimande.src}/lib">
            <include name="*.jar"/>
        </fileset>
    	<!-- include generated classes directory to classpath -->
    	<dirset dir="${build.dest.dir}" />
 
    </path>
 
    <!-- =================================================================== -->
    <!-- Initializes the build.                                              -->
    <!-- =================================================================== -->    
    <target name="init" description="Initialization">
 
        <!-- So that we can use the ${TSTAMP}, ${DSTAMP}, ... time stamps
             in targets, if need be -->
        <tstamp/>
 
        <echo message="---------- ${project.fullname} version ${project.version} ----------"/>
        <echo message=""/>
 
        <echo message="java.class.path = ${java.class.path}"/>        
        <echo message=""/>
        <echo message="java.home = ${java.home}"/>
        <echo message="ant.home = ${ant.home}"/>
        <echo message="user.home = ${user.home}"/>
        <echo message=""/>
        <echo message="basedir = ${basedir}"/>
        <echo message=""/>        
        <echo message="src.java.dir= ${src.java.dir}"/>
        <echo message=""/>        
        <echo message="build.dir= ${build.dir}"/>
 
    	<echo message=""/>        
	  <echo message="cimande.src = ${cimande.src}"/>
 
    </target>
 
    <!-- ================================================================== -->
    <!-- Displays usage information                                         -->
    <!-- ================================================================== -->
    <target name="usage" description="Displays usage information">
        <echo message="Use -projecthelp to see the available targets"/>
    </target>
 
    <!-- ================================================================== -->
    <!-- Perform clean, fetch, build, test, docs, and deploy     	    -->
    <!-- ================================================================== -->
    <target name="all" description="Calling All Target " depends="init, build, test">
        <echo message="Calling all the targets"/>
    </target>
 
    <!-- =================================================================== -->
    <!-- Cleans up the distribution                                          -->
    <!-- =================================================================== -->
    <target name="clean" description="Cleans up the distribution" >
    	<echo message="Clean out the output directories"/>
    	<delete quiet="false" includeEmptyDirs="true" failonerror="false">
        	<fileset dir="${build.dest.generated.dir}" />
        </delete>
    </target>
 
    <!-- =================================================================== -->
    <!-- Build the distribution                                              -->
    <!-- =================================================================== -->
    <target name="build" depends="init" description="Build the distribution" >
    	<echo message="Compiling all the code"/>
 
        <echo message=""/>        
        <echo message="src.java.dir= ${src.java.dir}"/>
        <echo message=""/>        
        <echo message="build.dest.dir= ${build.dest.dir}"/>
 
        <mkdir dir="${build.dest.dir}"/>
 
        <javac 
            classpathref="classpath"
            srcdir="${src.java.dir}/" 
            destdir="${build.dest.dir}" 
            debug="${debug}"
            deprecation="${deprecation}"
            optimize="${optimize}">            
        </javac>
 
    </target>
 
    <!-- =================================================================== -->
    <!-- Generate JavaDoc Documentation                                      -->
    <!-- =================================================================== -->
    	<target 
        name="javadocs" depends="build" 
        description="Generates the project's API documentation"
    >
        <mkdir dir="${javadocs.destdir}"/>
 
        <javadoc        
            sourcepath="${src.java.dir}" 
            destdir="${javadocs.destdir}"
            packagenames="org.blueoxygen.*"
            author="true"
            private="false"
            version="true"
            use="true"
            windowtitle="${project.fullname} API"
            doctitle="${project.fullname}"                
            bottom="Copyright &#169; ${year}, BlueOxygen Foundation. All Rights Reserved."
        >
            <classpath refid="classpath"/>
        </javadoc>
 
    </target>
 
    <!-- =================================================================== -->
    <!-- Ship the WARs and soon to the execution                       -->
    <!-- =================================================================== -->
    <target name="deploy" description="Ship the binary to the execution" >
    	<echo message="Deploying the code"/>
    </target>
 
    <!-- =================================================================== -->
    <!-- Run the junit test                                                  -->
    <!-- =================================================================== -->
    <target name="test" description="Test the distribution" >
    	<echo message="Testing"/>
    </target>
 
 
 
    <target name="update-schema" depends="init" description="Update the database schema">
        <path id="update.schema.classpath">
            <path refid="classpath"/>
            <pathelement path="${build.dest.dir}"/>
            <pathelement path="${src.config.dir}"/>
        </path>
 
        <taskdef name="update-schema" classpathref="update.schema.classpath"
                 classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"/>
 
        <update-schema quiet="no" text="no" drop="no" 
        	config="${src.config.dir}/hibernate.cfg.xml" />
        <echo message="Cimande schema updated"/>
    </target>
 
   <target name="create-schema" 
   		description="Generates DB schema with hbm2ddl." 
        depends="init, build">
  	<!--
   	<mkdir dir="${build.dir}/generated/sql"/>

   	-->
   	<taskdef classpathref="classpath"  name="hibernatetool" 
   	classname="org.hibernate.tool.ant.HibernateToolTask" />
 
   	<hibernatetool destdir="${build.dir}/generated/sql">
   	 <annotationconfiguration
   	  		configurationfile="${src.config.dir}/hibernate.cfg.xml"/>
 
   	 	<!-- list exporters here -->
        <!-- outputfilename="cimande-schema.ddl" -->
   		<hbm2ddl 
   			update="true"
   			export="true" 
   			drop="true"
   		 	delimiter=";"
   		 	format="true"
   		/>
   	</hibernatetool>
 
    </target>
 
 
	 <!-- =================================================================== -->
	    <!-- Export from Database to XML                        -->
	    <!-- =================================================================== -->
	    <target name="dbexport" description="dump database to xml" >
	    	<echo message="Dump Database to XML"/>
	    	<mkdir dir="${build.dir}/generated/dbxml"/>
	    	<taskdef  
	    			name="dbunit" 
	    			classname="org.dbunit.ant.DbUnitTask"
	    			classpathref="classpath"
	    	/>
 
	    	<dbunit driver="${db.driver}"          
	    			    	        url="${db.url}"          
	    			    	        userid="${db.user}"          
	    			    	        password="${db.password}">
 
	    	    <export 
	    	    	format="xml"
	    	    	dest="${build.dir}/generated/dbxml/${project.name}-${project.version}-export.xml"/>
	    	    	<!-- dest="${build.dir}/src/sql/${project.name}-${project.version}-export.xml"/>
 -->
	    	</dbunit>
	    </target>
 
	<!-- =================================================================== -->
		    <!-- Import from XML to Database		-->
		    <!-- =================================================================== -->
 
	<target name="dbimport" description="fill database from xml" >
		    	<echo message="Fill Database from XML"/>
 
		    	<taskdef name="dbunit" classname="org.dbunit.ant.DbUnitTask" classpathref="classpath" />
		    	<dbunit driver="${db.driver}"
		    		supportBatchStatement="false" 
		    	        url="${db.url}"          
		    	        userid="${db.user}"          
		    	        password="${db.password}">
		    		<operation type="CLEAN_INSERT"
					src="${build.dir}/src/sql/${project.name}-${project.version}-export.xml"/>
 
		    			<!--
		    			src="${build.dir}/generated/dbxml/${project.name}-${project.version}-export.xml"
 
		    			format="xml"/>

							--> 		  
		    	</dbunit>
	</target>
    <target name="create-jar" depends="build" description="Create JAR" >
    	<echo>Copy template files </echo>
    	<mkdir dir="${build.dest.view.dir}"/>
    	<copy todir="${build.dest.view.dir}">
    		<fileset dir="${src.view.dir}" />
    	</copy>
 
    	<echo>Copy struts xml files to classes</echo>
    	<mkdir dir="${build.dest.bundle.dir}"/>
 
 		<copy todir="${build.dest.dir}">
             <fileset dir="${src.java.dir}" includes="*.xml"/>
         </copy>
    	<!-- Create Jar -->
    	<jar
        jarfile="${build.dest.jar.dir}/${project.name}-${project.version}.jar" 
        basedir="${build.dest.generated.dir}/classes"       
        />
    </target>
 
	<target name="create-sdk-bundle" depends="create-jar" description="Generate and assemble configuration">
 
		<copy todir="${build.dest.blank.dir}/WebContent/WEB-INF/lib">
		    <fileset dir="${build.dest.jar.dir}" includes="${project.name}-${project.version}.jar"/>
		</copy>
 
		<mkdir dir="${build.dest.blank.dir}/src/config"/>
 
		<copy todir="${build.dest.blank.dir}/src/config">
    	            <fileset dir="${cimande.src}/src/config" />
    	</copy>
 
		<mkdir dir="${build.dest.blank.dir}/src/java"/>
		<mkdir dir="${build.dest.blank.dir}/src/template"/>
		<mkdir dir="${build.dest.blank.dir}/src/sql"/>
 
		<echo message="Copying .sql to blank/src/sql"/>
 
		<copy todir="${build.dest.blank.dir}/src/sql">
    	            <fileset dir="${build.dir}/src/sql" includes="*.sql"/>
    	</copy>
 
		<copy todir="${build.dest.blank.dir}">
    	    <fileset dir="${build.dir}" includes=".classpath"/>
    	    <fileset dir="${build.dir}" includes=".project"/>
    	</copy>
 
 
		<echo message="Copying WebContent to blank"/>
		<mkdir dir="${build.dest.blank.dir}/WebContent"/>
 
		<copy todir="${build.dest.blank.dir}/WebContent">
    	            <fileset dir="${cimande.src}/WebContent" />
    	</copy>
 
		<jar
			jarfile="${build.dest.bundle.dir}/${project.name}-${project.version}-sdk.zip" 
			basedir="${build.dest.blank.dir}"       
        />
 
    </target>
 
	<target name="war" depends="create-sdk-bundle" description="Create web-app WAR">
			<mkdir dir="${build.dest.blank.dir}/WebContent/WEB-INF/classes"/>
			<copy todir="${build.dest.blank.dir}/WebContent/WEB-INF/classes">
		    	<fileset dir="${cimande.src}/src/config" />
		    </copy>
 
        	<war destfile="${build.dest.bundle.dir}/${project.name}-${project.version}.war" webxml="${build.dest.blank.dir}/WebContent/WEB-INF/web.xml">
            <fileset dir="${build.dest.blank.dir}/WebContent">
            </fileset>
        </war>
    </target>
 
</project>

[edit] build.properties

deployer.target=C:/blueoxygen/papaje-dev/WebContent/WEB-INF/lib
cimande.src=C:/blueoxygen/cimande-blank

[edit] db.properties

db.url=jdbc:mysql://localhost/cimande?&sessionVariables=FOREIGN_KEY_CHECKS=0
#db.url=jdbc:mysql://localhost/cimande
db.user=root
db.password=tulalit
db.driver=com.mysql.jdbc.Driver
Personal tools