springboot packaging and deployment project

1, springboot project lib packages, config configuration file is packaged configuration.

        maven is actually made up of a variety of plug-ins, executing mvn command, corresponding maven plug-ins are called to prototypes, such as mvn compile, mvn install, etc. is called maven-compiler-plugin, maven- install-plugin plugin. The plug-in is packaged using a configuration file in the pom, pom in which plugins case the  plugin real use, and  pluginManagement under the  plugins under  plugin is just a statement. After the introduction of the plug-pom can see the corresponding plug-in local warehouses.

       When packing, we hope that the project depends on the jar package to package lib directory, configuration files are packaged individually to the config directory (where the project do not enter the jar package, easy to modify the configuration file when the late deployment of O & M), a project separate jar package and lib directory, config directory at the same level directory. pom configuration file as follows:

 

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.nrxt.ns5000.kafkatodb.SpringbootApplication</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>

</plugins>
</pluginManagement>


<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.XXX.SpringbootApplication</mainClassXXX>
</manifest>

<manifestEntries>
<!--MANIFEST.MF 中 Class-Path 加入资源文件目录 -->
<Class-Path>./config/</Class-Path>
</manifestEntries>

</archive>

<excludes>
<exclude>config/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<!- effect of the plug is used to copy a specified file -> <Executions><the artifactId> Resources-Maven-plugin </ the artifactId>
<plugin>


<execution> <!-- 复制配置文件 -->
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources/config</directory>
<includes>
<!-- <include>*.properties</include> -->
</includes>
</resource>
</resources>
<outputDirectory>${project.build.directory}/config</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>


</plugins>

</build>

 

        Require special note is, addClasspath representative adds a classpath, on behalf of classpathPrefix the contents of the lib / directory are added to the class path, mainClass specify start the main class, on behalf of Class-Path to config directory to resource directory, this information is recorded in Manifest.mf project jar file package, the time to perform jar package, will find this file in accordance with the startup class, where the class path dependent jar, and configuration files. Here classpath lib / is a relative path, so deployment time to pay attention, lib directory to the directory where the package placed in the jar project, because when you run the jar package will go to the lib / directory based on Manifest.mf file is located in the jar directory If placed in the wrong position, and will report the error you can not find the class.

2, linux under the project deployment

(1) Add User 

groupadd -g 202 usergroup

useradd -u 2021 -d /home/user -g usergroup-s /bin/csh -m user

passwd user

(2) installed jdk, and configure the environment variables

   Here mainly referring to the next environment variable configuration, if you set the environment common jdk environment variable is configured in / etc / profile Lane. If only java environment variables in the user, it .bashrc in the user's home directory

Or the lower set .cshrc, csh and bash configurations are different. Because of my users are using csh, so I command in .cshrc:

 

# .cshrc

setenv JAVA_HOME /usr/java/jdk1.8.0_121
setenv CLASSPATH .:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
setenv PATH $JAVA_HOME/bin:/bin:/usr/sbin:/usr/bin:/root/bin

       Note here, the add / bin under the if not path: / usr / sbin: / usr / bin: / root / bin, will lead pwd, ll, vim commands will be unavailable when the execution command to the PATH variable specified find the path to see if you can find the appropriate command program. If you do not add $ JAVA_HOME / bin, can not find the version of jdk, java command can not be executed, execution will go to the directory to find javac java jar and other tools java command.

If you are using bashrc, then the environment variable configuration is necessary to use export:

 

# .bashrc

EXPORT JAVA_HOME=/usr/java/jdk1.8.0_121
EXPORT CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
EXPORT PATH=$JAVA_HOME/bin:/bin:/usr/sbin:/usr/bin:/root/bin

Once configured, source .cshrc or source .bashrc refresh the environment variables, java -version view jdk version number.

 

(3) and start deployment project

   The project jar package test.jar, lib /, config / directory uploaded to the user's home directory, and create logs directory, and then use java -jar test.jar to start the project.

      

Guess you like

Origin www.cnblogs.com/luckyna/p/11563195.html