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:
- 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.
- build.sh: This is also very important we will use this file to build project from command line:
- deployment.sh: 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: RunApplication.java 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 message.properties file.
- message.properties: 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:
- That’s it. For more information please refer maven build documentation here
Download Project: RunProjectBatchFile