springboot jar分离部署

springboot jar分离部署

  • 注意:spring boot web项目别使用jsp页面,可以使用模板代替,jsp打包时访问页面会报404错误。

1.具体配置如下:

<build>
        <plugins>
            
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-jar-pluginartifactId>
                <version>3.1.1version>
                <configuration>
                    <archive>
                        <manifest>
                            
                            <addClasspath>trueaddClasspath>
                            
                            <classpathPrefix>lib/classpathPrefix>
                            <mainClass>com.ms.serviceapi.ServiceapiApplicationmainClass>
                        manifest>
                    archive>
                    
                    <excludes >
                        <exclude>**/*.propertiesexclude>
                        <exclude>**/*.xmlexclude>
                        <exclude>**/*.ymlexclude>
                    excludes>
                configuration>
            plugin>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-dependency-pluginartifactId>
                <executions>
                    <execution>
                        <id>copy-libid>
                        <phase>packagephase>
                        <goals>
                            <goal>copygoal>
                        goals>
                        <configuration>
                            <outputDirectory>target/liboutputDirectory>
                        configuration>
                    execution>
                executions>
            plugin>
            

            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-antrun-pluginartifactId>
                <executions>
                    <execution>
                        <phase>packagephase>
                        <goals>
                            <goal>rungoal>
                        goals>

                        <configuration>
                            <target>
                                <property name="dist" value="target/publish">property>
                                <property name="dist-tmp" value="${dist}/tmp">property>
                                <property name="app-name" value="${project.artifactId}-${project.version}">property>

                                <copy file="target/${app-name}.jar" tofile="${dist}/${app-name}.jar" />
                                <delete dir="${dist}/${app-name}-classes.jar" />

                                
                                <delete dir="${dist-tmp}" />

                                <move todir="${dist}/lib">
                                    <fileset dir="target/lib" />
                                move>

                                <copy todir="${dist}">
                                    <fileset dir="target/classes">
                                        <include name="**/*.properties" />
                                        <include name="**/*.xml" />
                                        <include name="**/*.yml" />
                                    fileset>
                                copy>
                            target>
                        configuration>
                    execution>
                executions>
            plugin>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-resources-pluginartifactId>
                <configuration>
                    <delimiters>
                        
                        <delimit>${*}delimit>
                    delimiters>
                configuration>
            plugin>
            
        plugins>
    build>

2.打包目录如下:

lib
xxx.yml
xxx-1.0.jar

3.运行:

java -jar -Dloader.path=lib xxx.jar

4.assembly复制打包后的文件

<plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-assembly-pluginartifactId>
                
                <configuration>
                    
                    <descriptors>
                        <descriptor>src/main/resources/assembly/package.xmldescriptor>
                    descriptors>
                configuration>
                <executions>
                    <execution>
                        <id>make-assemblyid>
                        <phase>packagephase>
                        <goals>
                            <goal>singlegoal>
                        goals>
                    execution>
                executions>
            plugin>

4.1 package.xml配置文件


<assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>packageid>
    <formats>
        <format>tar.gzformat>
        <format>dirformat>
        <format>zipformat>
    formats>
    <includeBaseDirectory>trueincludeBaseDirectory>
    
    <dependencySets>
        <dependencySet>
            
            <outputDirectory>liboutputDirectory>
        dependencySet>
    dependencySets>
    
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/classesdirectory>
            <outputDirectory>/outputDirectory>
            <includes>
                <include>**/*.propertiesinclude>
            includes>
        fileSet>
 
        
        <fileSet>
            <directory>${project.build.directory}directory>
            <outputDirectory>/outputDirectory>
            <includes>
                <include>*.jarinclude>
            includes>
        fileSet>
    fileSets>
     <files>
        
        <file>
            
            <source>pom.xmlsource>
            
            <outputDirectory>.outputDirectory>
            
            <fileMode>0755fileMode>
            
            <destName>pom.xmldestName>
        file>
    files>
assembly>

你可能感兴趣的:(java,spring,boot,jar,后端)