Automatically build Web applications using Gitlab, MAVEN, Docker __web

Source: Internet
Author: User
Tags docker cp docker run java se

Every time a team builds an application, it is troublesome and error-prone to export the war package through eclipse/sts, then upload it to the server, copy it to Tomcat, and manually stop/start the Tomcat service.

I used Gitlab, MAVEN, Docker tools, plus a shell script, to make a simple automated build tool.

1. First install JDK version 64, MAVEN, modify/etc/profile file as follows:

jre_home= $JAVA _home/jre
#CLASSPATH =.: $JAVA _home/lib: $JAVA _home/jre/ Lib
classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/rt.jar: $JAVA _home/lib/tools.jar: $JRE _home/lib/rt.jar
Export maven_home=/home/git/src/apache-maven-3.5.2

Path= $JAVA _home/bin:/home/git/apache-maven-3.5.2/bin: $PATH
export java_home CLASSPATH jre_home PATH
tz= ' Asia/shanghai '; Export TZ

2. Install Docker and use Docker to install Gitlab, you can refer to my previous blog.

2.1 Download the Tomcat image and start.

sudo docker pull Tomcat
sudo docker cp/etc/localtime gitlab:/etc/localtime   #解决容器和主机时间不一致问题

sudo docker run -d-p 8080:8080--name Customer Tomcat

After startup, you can enter the Docker Tomcat instance to confirm the Tomcat storage location.

sudo docker exec-it Customer/bin/bash

root@f945b6723f41:/usr/local/tomcat# CD webapps/

root@f945b6723f41:/usr/local/tomcat/webapps# pwd


root@f945b6723f41:/usr/local/tomcat/webapps# ls

Cumstomermanage ROOT Examples Manager

Cumstomermanage.war Docs Host-manager


3. Write the automatic build script file.


cd ~/customermanage_web/

git pull

MVN Package- Dmaven.test.skip=true

sudo docker restart customer

sudo docker cp ~/customermanage_web/target/ Cumstomermanage.war customer:/usr/local/tomcat/webapps


sudo docker restart customer

Add script execution permissions when finished.

chmod 755

PS. This place also solves a MVN package compilation problem, MVN packge when prompted [Maven]package Com.sun.image.codec.jpeg does not exist

Oracle has retired from all of Com.sun's bags since jdk7.

Synopsis:the Non-standard Com.sun.image.codec.jpeg Package is retired description:the

Package is added in JDK 1.2 (DEC 1998) as a non-standard way of controlling the loading and saving of JPEG format image f Iles. This package is never part of the platform specification and it has been removed to the Java SE 7 release. The Java Image I/O API is added to the JDK 1.4 release as a standard APIs and eliminated the need for the Dec.jpeg package.

To solve this problem, just add it to the Pom file

				<version>2.5.1</ version>
					<compilerargument>-xdignore.symbol.file</compilerargument >

4. Execute the script, confirm the execution result


5. The team member used to feel very convenient, and then came up with a small need to automatically generate daily version of the day, the test the next morning to verify the latest code, the implementation is also very simple, in the crontab to add timed tasks.


# m H  Dom Mon Dow   command
0 1 * * * */home/git/

The first argument is the minute, the second parameter is the hour, and the latter several * represent running daily.

After the end, after the follow-up if there is time to toss down the Jenkins, to achieve continuous integration.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.