Create Build Run Project Batch File

Create Build Run Project Batch File

This is one of the big task in any project which perform by Senior member in the team. Here Senior member of the team is responsible for set up project from scratch one set up is done he will create build script, deploy script and run script to make project run live on different environment. I never saw no where on the internet which can teach us how to perform this task and writing here to help how this works:


Note: We will use Spring framework for this demo with Maven.

  • Create maven project name: RunProjectBatchFile below is complete details of the project:

Create Build Run Project Batch File

  • pom.xml: Look this file seriously everything seems OK except build tag where we are using plug-in which will copy all jar file to lib folder.

  • This is also very important we will use this file to build project from command line:

  • This file will be use for deployment to deployment folder:

  • run-script.bat: Batch file which will be use to run the project:

As you see in the project structure we have very simple maven project with two class: main file to run the application and ValidateBuild where we have one method which will print “Build is working!!!” on th console to verify the application if everything is working as expected. Please have these class below:



As you see in above class we have one method where it read variable value from file.

  • To keep message in use in classes

  • log4j2.xml: For logging

  • spring-context.xml: As we are using Spring as framework for this application so this is main file which works as container:

That’t it. Now go to command prompt CD to you project location then to to deployemnt directory and in my case it’s as below and type below command and press enter maven will start building the project:


  • Once its done you will see below success message on the console:

  • Now cd to deployment folder and execute below command:


  • This will deploy files to the deployment directory and it’s location will be one folder up from project location.
  • Now we are all done cd to below folder and execute below command you will see “Build is working!!!” message on the console:


#! /bin/sh  cd ../../.. WORK_DIR=`pwd` echo "working directory $WORK_DIR"  # pass this as argument DEPLOYMENT_DIR=$WORK_DIR/../deployment	 echo "deployment directory $DEPLOYMENT_DIR"   if [ -d "$DEPLOYMENT_DIR" ]   then    echo "folder $DEPLOYMENT_DIR exists. deleting it for clean deployment"       rm -rf  $DEPLOYMENT_DIR fi  mkdir $DEPLOYMENT_DIR   # Multiple proejct example: PROJECT_LIST=(Project1 Project2 Project2) PROJECT_LIST=(RunProjectBatchFile)  for PROJECT_NAME in  ${PROJECT_LIST[@]} do   	echo "Project Name >> $PROJECT_NAME" 		 	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME 	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/lib 	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/scripts/ 	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/runWindow/ 	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/logs 	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/config 	 	echo "copying jar into $DEPLOYMENT_DIR/$PROJECT_NAME/lib/ ..." 	cp $PROJECT_NAME/target/lib/* $DEPLOYMENT_DIR/$PROJECT_NAME/lib/ 	cp $PROJECT_NAME/target/*.jar $DEPLOYMENT_DIR/$PROJECT_NAME/lib/ 	 	echo "copying scripts into $DEPLOYMENT_DIR/$PROJECT_NAME/scripts/ ..." 	cp $PROJECT_NAME/scripts/deployment/* $DEPLOYMENT_DIR/$PROJECT_NAME/scripts/ 	 	echo "copying xml and properties file to $DEPLOYMENT_DIR/$PROJECT_NAME/config/ ..." 	cp $PROJECT_NAME/src/main/config/* $DEPLOYMENT_DIR/$PROJECT_NAME/config/ 	cp $PROJECT_NAME/src/main/resources/* $DEPLOYMENT_DIR/$PROJECT_NAME/config/ 	 	echo "copying runtime window file to  $DEPLOYMENT_DIR/$PROJECT_NAME/runWindow/" 	cp $PROJECT_NAME/scripts/runWindow/* $DEPLOYMENT_DIR/$PROJECT_NAME/runWindow/	 	 	echo "copying runtime file to  $DEPLOYMENT_DIR/$PROJECT_NAME/runWindow/" 	#Other folder copy example: cp Parent/scripts/runtime/* $DEPLOYMENT_DIR/$PROJECT_NAME/scripts/ 	 done;   echo "copying windows task file to $DEPLOYMENT_DIR/window_task/" mkdir $DEPLOYMENT_DIR/window_task/ # Window take copy example: cp -r Parent/scripts/window_task/* $DEPLOYMENT_DIR/window_task/  echo "exiting after completion of deployment" exit 0

  • That’s it. For more information please refer maven build documentation here

download Download Project: RunProjectBatchFile

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *