Several deployment methods for Springboot to generate jar packages:
The first form of deployment: foreground startup
Java –jar afwcs-start-1.0.0.jar
Projects deployed in this way belong to the front-end deployment form. Once the page is closed, the project will also be closed. If you continue to request the interface, nothing will be returned, indicating that the current project has died.
When we close pages such as xshell , the program will stop .
The second form of deployment: background startup
Gateway:
nohup java -jar gateway-0.0.1.jar >gatewaylog.file 2>&1&
calculate:
nohup java -jar afwcs-start-1.0.0.jar >afwcslog.file 2>&1&
Directory after startup:
Log directory generated after startup
The project started in this case will generate two logs:
One gatewaylog.file and one GATEWAY-info.2019-06-12.log, and the contents of the two logs are exactly the same.
The third deployment method: no nohup logs
So if we don't want nohup logs, we can directly put the logs into the black hole: nohup java - jar ***. jar --server.port=9091 >/dev/null 2>&1 &
or:
nohup java -jar xxx.jar >/dev/null &
Generally, this kind of program ends with & . But if the terminal is closed, the program will also be closed .
There is also a special file /dev/null under Linux, which is like a bottomless pit, and all information redirected to it will disappear without a trace.
Gateway:
nohup java -jar gateway-0.0.1.jar >/dev/null 2>&1&
calculate:
nohup java -jar afwcs-start-1.0.0.jar >/dev/null 2>&1&
For projects deployed in this case, the logs are in the logs under the gateway directory, which makes it easy to check that no redundant logs are generated.
Explanation: 2> means redirecting the standard error (stderr). The angle brackets can be followed by the file name, indicating which file the output information is to be written to (or not written, the default output is to nohup.log), or &1 , &2, indicating redirection to standard output and standard error respectively.
Fourth method: Specify external configuration file
The Spring program will load the application.properties configuration file from the following paths according to priority.
1./config directory in the current directory
2.Current directory
3./config directory in classpath
4.classpath and directory
Therefore, it is very simple to add an external configuration file. Create a new config folder in the directory where the jar is located, and then put the configuration file in it, or directly place the configuration file in the jar directory.
Use the configuration file outside the jar package to replace the configuration file within the project:
nohup java -jar gateway-0.0.1.jar --spring.config.location=/usr/local/jarPackage/gateways/application-dev.properties >/dev/null 2>&1&
After testing, the project can be started normally and data can be run.