An article about the jar package Shell STARTUP script of Maven project, mavenjar
Maven is used as the management of project jar package dependencies. It is often used to start a command line. I am also a novice developer. During microservice and server development, the main method is often used to start a project. I have studied a lot of blogs and found that most of the posts are scattered and have not been designed for application scenarios. I would like to summarize them here, on the one hand, as your own learning notes, and on the other hand, as your technology
Here is the startup script of a project I have written.
1: In the wins editor, the line break is \ r \ n, and the linux line break is \ n, so we have edited it. sh STARTUP script, you will find that {\ r is not an internal command, xxxx line script error occurs, here as a developer must pay attention to, then, how to solve it, use notePad ++. Choose ---- "view -----" symbol display ---------- "show all symbols
Then open search and replace as follows
After replacement. Shown as follows:
Compared with the first figure, is the line break different?
The following describes some Startup Script Parameters and startup commands.
SERVER =/usr/local/netty/mqtt here is the storage path of our packaged jar package
Echo console output prompt, just like our example E. out. println ()
JAVA_HOME JDK installation path
Cd switch directory
ClassPath jar package storage directory
Nohup linux Command Execution
Java-cp top-transfer.jar com. top. application. mqtt. activit. ActivitReceiveTopic start & java VM start main method command
Note: java-cp top-transfer.jar com. top. application. mqtt. activit. activitReceiveTopic start can also be used as a separate mian method startup command. It is only in this way that the process is not started. When we close the console, the process is closed, the started process is also closed, and the program will not continue to run.
Next, let's take a look at the packaging method of the Maven project. As mentioned above, the maven project will reference many other jar package dependencies, at this time, we need to package the third-party jar package reference to our project at the same time, so that Mavne has completed the plug-in.
The commonly used plug-in maven-assembly-plugin is widely used.
Add the following code to pom. xml:
We package maven for the developed project.
The following prompt is displayed after running:
Build success indicates that the package is successful. Find the package directory and see two jar packages. decompile the package to see the content of the jar package.
The Decompilation result is as follows. The first package does not have a jar package dependency.
Check the second package. The following shows our configuration file. all third-party jar packages are packaged.
Note that there is a MANIFEST. MF file in the jar package, and the configuration information of the packaged jar package is found in this file, which is equivalent to the same specification.
Note that the packaging plug-in mentioned above contains such a line of code
Create the main method of the jar package in the mainClass label, and add the main method during the period.
Then we re-package and decompile the second jar package.
With the main method added, the startup window of the jar package is developed. Packaging is complete now
In linux, we also need to use chmod a + x startup. sh to add the edited script to the shell startup script in the northern part of linux.
Run./startup. sh.