“Take a cup of water in the sky, according to the moon world shake ah shake” mobile phone call came, a look at the original is the boss’s phone, looking for me certainly no good.

“Xiao Fei, just XXX project customer called over, said the mobile phone number can not be registered, hurry to see what the problem!” The boss said.

“Yes, Sir.” I replied gently to my boss. After hanging up the phone, I quickly took out my computer.

“No, how could there be a problem with registering an interface? Mobile phone number + SMS verification code + password to complete the registration, very easy ah.” I thought as I turned on my computer.

Computer startup success, open MobaXterm connected to the server, easy way to click the command to view the log

less log.out
Copy the code

Ps: This section describes common commands of less

G moves to the last row

G goes to the first row

? Excep Searches for the content containing “Excep”, press Enter, n to scroll up, n to scroll down

/excep To search down the content containing “excep”, press Enter, n to scroll down, n to scroll up

Type G to scroll to the last line and look for exceptions

? exceptionCopy the code

Press enter, n look up, NullPointerException

java.lang.NullPointerException: null
    // We can see that the error exception is thrown in which class and line of code
        at com.hn.project.contorller.UserController.register(UserController.java:306)
Copy the code

Open the IDEA development tool, double-click Shift, and search for the UserController class.

Ctrl+G, type 306 and click OK to jump to line 306.

“Oh, this is where the null pointer exception was reported!” “I said aloud.

The registration interface is used in two places:

  • H5 page invite registration, you need to bring the invitation code to register.
  • App registration, do not need to carry the invitation code

Since the invitation code is not mandatory, I do not need to make a short call condition. However, if the invitation code exists, the invitation relationship must be bound. Because the invitation code is not transmitted, the invited user information cannot be queried, and a null pointer exception is reported.

“Ok, package the deployment server.” I said.

Package upload, to make a cup of milk tea to drink, JAR package upload should be about the same.

Milk tea bubble good, come back a look, “I wipe, how just upload so point?” See upload speed is only 10K /s, suddenly a clap thigh, flow yesterday began to be limited. There is no wireless network in the rented place, and I use the data flow at home every day. Isn’t it the end of the month? More than 10G, the speed limit, hurriedly to my wife for help, she gave me a, her early was the speed limit. How do you do that? Look at slow with snail like network speed, then had the following god general operation.

Online packaging

Maven environment

  1. Maven is installed on the server. If the project goes live, it is best to find a test server. Do not use the server of the live project, because packaging will take up server resources.
  • Download the Maven installation package
Wget HTTP: / / https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gzCopy the code
  • Unpack the maven
The tar XVF - apache maven - 3.6.3 - bin. Tar. GzCopy the code

  • rename
Mv apache maven - 3.6.3 MVNCopy the code
  • Move to the /usr/local directory
mv  mvn/ /usr/local/
Copy the code

  • Configuring environment Variables
vim /etc/profile
Copy the code

Add the following

#set maven
MAVEN_HOME=/usr/local/mvn
export MAVEN_HOME
export PATH=${PATH}:${MAVEN_HOME}/bin
Copy the code

  • let/etc/profileThe modification takes effect immediately
 source /etc/profile
Copy the code
  • Verify that the installation is complete
mvn -v
Copy the code

  1. Upload the source code to the server

  • Compressed source code

  • Open theMobaXterm, upload source code

  • Unzip the source code
unzip -d mvnDemo mvnDemo.zip
Copy the code

If you do not have the unzip command, run the yum install -y unzip zip command to install it

  1. performmvn packagepackage
  • Open themvnDemoDirectory, run the command to package

mvn package -Dmaven.test.skip=true
Copy the code

-dmaven.test. skip=true Package skips test

  • Open thetargetDirectory, we can see the generated JAR package

  1. Start the jars
  • Start jar packages in the background
Nohup Java -jar demo-0.0.1 -snapshot.jar > log.out 2> &1&Copy the code
  • Viewing Dynamic Logs
tail -f log.out
Copy the code

  1. Test whether the interface can be accessed normally
 curl http://localhost:8080/test
Copy the code

Gradle environment

  • Download the Gradle installation package
Wget HTTP: / / https://downloads.gradle.org/distributions/gradle-6.8.3-all.zipCopy the code
  • Unpack the installation
Unzip gradle-6.8.3-all.zip mv gradle-6.8.3 /usr/local/cd /usr/local mv gradle-6.8.3 gradle mkdir -p =/usr/local/gradle/.gradleCopy the code
  • Environment Variable Configuration
vim /etc/profile
Copy the code

Add the following

export GRADLE_HOME=/usr/local/gradle
export PATH=${GRADLE_HOME}/bin:${PATH}
export GRADLE_USER_HOME=/usr/local/gradle/.gradle
Copy the code
  • Heavy-duty environment configuration
source /etc/profile
Copy the code
  • Check whether the installation is successful
gradle -version 
Copy the code

The upload code is the same as MVN, except that the packaging command is different

  • Gradle packaging
gradle bootJar
Copy the code
  • Jar package generation directory, build/libs/
cd build/libs
Copy the code
  • The background to start
Nohup Java -jar demo-0.0.1 -snapshot.jar > log.out 2> &1&Copy the code

Quadratic optimization

Our compiled code is actually not much, the main space is the dependency jar package, we start the dependency jar package to a specified directory on the server, we start the service to specify the lib directory is ok? Let’s try it out

  • Create a lib folder

  • Use the compression software to open the JAR packages and copy all the JAR packages in the boot-INF /lib directory to the newly created lib directory

  • Delete all JAR packages in the boot-INF /lib directory

    java -Djava.ext.dirs=./lib -jar test.jar
    Copy the code

Note: If you have a new dependent JAR package, you need to drag the new jar package to the lib directory separately.

Every time you finish the package, you have to manually delete the dependent JAR package. Can you exclude the JAR package when you package it?

  • Gradle configuration

    // Add the following code to build.gradle
    bootJar {
    	archiveClassifier = 'boot'
    	excludes = ["*.jar"]}Copy the code

reference

Unzip Decompresses the file to a specified directory

Centos 7 Install Gradle