Deploy java project (2)-install plug-in, build job, manually install jdk, publish war package

Install plugin

First install two plug-ins in the jenkins interface:

System management—>Manage plugins, install two plugins: Maven Integration and Deploy to container. The Maven Integration plug-in is used to build maven projects, and Deploy to container is used to publish war packages to remote machines.

imgimgimgimg

After installing the plugin, restart jenkins:

[root@jinkai src]# systemctl restart jenkins

Log in to jenkins again and build the maven project:

img

Configure maven project

After clicking OK above, Jenkins will automatically transfer to the configuration interface of the project, and we need to perform some configuration.

Description here to customize

img

For source code management, select Git, then Repository URL fill in the address of the repository in the gitlab server we built, Credentials, select Add on the right, and add credentials

img

Type select SSH Username with private key, user name is customized, private key here is the private key corresponding to the public key on the jenkins machine and gitlab.

Check the private key corresponding to the public key on the jenkins machine and gitlab (when we cloned the repository before, we passed the public key on the jenkins machine to the gitlab server)

[root@jinkai src]# cat /root/.ssh/id_rsa

We did not set a password when generating the key pair, so the Passphrase can be left blank, and the following is also blank, just click add

img

Credentials choose Git, you can find that the previous red prompt is gone, indicating that there is no problem

img

Build triggers, build environment, and Pre Steps are all kept as default; Root POM under Build is pom.xml, Goals and options fill in clean install -D maven.test.skip=true; Post Steps and build settings are kept by default;

img

Click to add post-build operation steps, select Deploy war/ear to a container, fill in WAR/EAR files * / .war, which means all war packages; leave the Contex path blank; select Tomcat 8.x for Containers, and fill in Tomcat URL to install tomcat The address of the server, mine is http://192.168.111.137:8080

img

Credentials click Add, the user name here is tomcat, the password is admin123, the user name and password here is the account and password for logging in to the tomcat back-end management entrance, the others keep the default, just add

img img

Then select admin/ ** for Credentials

img

Continue to click to add post-build operation steps, select Editable Email Notification, Project Recipient List here to add your own mailbox, separated by English commas, and keep the default in other locations

img

Pull down the lower left corner and click Advanced Setting, locate Triggers, you can add conditions for sending emails at Add Trigger, if it is Always, it’s fine.

img

Finally, click Apply and Save.

Build now

After the above configuration is complete, we start to build. Click to create now

img

Then we select #1 under the build history, drop down and click on the console output, you can see the output we just built

img

The first build will be slightly slower, because it will download a lot of maven-related things, check the final result, there is an error here

img

View mailbox mail

img

Go back to the jinkai01 machine and install jdk:

Because jdk was installed on the jinkai02 machine when tomcat was installed before, so I can directly copy from jinkai02 to jinkai01 here

[root@jinkai src]# scp -r 192.168.111.137:/usr/local/jdk-14 /usr/local/jdk-14

[root@jinkai src]# ls /usr/local/jdk-14/

bin conf include jmods legal lib man release

Go back to the jenkins interface, go back to the home page, click System Settings → Global Tool Configuration → JDK, alias customization, and then fill in the path where you just installed jdk, then apply and save

img img

Restart the jenkins service:

[root@jinkai src]# systemctl restart jenkins

Log in to the jenkins interface again, return to java-test, build again, and check the console output

img

img

View mailbox mail

img

Change the source of maven to the address of Alibaba Cloud

[root @ jinkai ~] # vim /usr/local/src/apache-maven-3.6.3/conf/settings.xml

<mirror>

<id>nexus-aliyun</id>

<mirrorOf>central</mirrorOf>

<name>Nexus aliyun</name>

<url>http://maven.aliyun.com/nexus/content/groups/public</url>;

</mirror>

The original error was reported for hours after rebuilding, but there is still an error, which has not been resolved, let’s talk about it later

our

In summary, there are two main points:

1) When maven compiles zrlog source code, it will read the pom.xml of zrlog, it uses maven 2 version, and the maven we downloaded is version 3, so jenkins will automatically help us to download version 2 maven library, this The process is very, very slow, and many students are stuck here.

The solution to this problem is to replace the source of maven with the address of Alibaba Cloud. Method reference:

https://blog.csdn.net/zl1zl2zl3/article/details/83589977

2) The database configuration is defined in the zrlog source code, the specific path is here

Old version: src/main/webapp/WEB-INF/db.properties

New version: web/src/main/webapp/WEB-INF/db.properties

The default database server is

demo.blog.zrlog.com:3306 Therefore, in the old video, we can directly access the blog after deployment, because it directly accesses the database of this server. The current database has been down, so everyone directly reported an error when deploying.

The idea to solve this problem is:

In the source code, directly define the database information, for example: database server 127.0.0.1 database zrlog user zrlog password lishiming, the configuration file is like this:

driverClass=com.mysql.cj.jdbc.Driver

user=zrlog

password=lishiming

jdbcUrl=jdbc\:mysql\://127.0.0.1\:3306/zrlog?characterEncoding\=UTF-8&useSSL\=false&serverTimezone\=GMT

In order to facilitate your experiments, students can use this repository https://github.com/aminglinux/zrlog/ , the configuration file has been modified to the above content.

Note: The premise of this is that you need to create a zrlog library first, authorize zrlog users, I put the database sql file in the source code (path: zrlog/data/zrlog.sql), and you import sql into mysql by yourself.

imgimg

Guess you like

Origin blog.51cto.com/11451960/2640814