一.springboot 打包成jar
1.pom.xml
<build> <!-- jar的名稱--> <finalName>shiro</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- 1、設置jar的入口類 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>com.cd.shiro.Application</mainClass> </manifest> </archive> </configuration> </plugin> <!--2、把附屬的jar打到jar內部的lib目錄中 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <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> <!-- 3、打包過程忽略Junit測試 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> <!-- 過濾resources 下的html--> <resources> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> <excludes> <exclude>html/**</exclude> </excludes> </resource> </resources> </build>
2、maven打包:mvn clean package
生成的jar包會在項目的target目錄下
3、運行jar包,命令行下:
java -jar xxxx.jar
4、父子工程項目,可在父工程pom.xml中指定打包到統一目錄中,上面步驟二將附屬jar打包到lib ${project.build.directory} 就是路徑
注意:如果此方式出現打包后的數據混亂請使用方法5.
<build>
<!--項目打包路徑 比如源代碼在 f:/project 會打包生成在f:/target下面.
如何部署?
兩種方式:
一:只上傳合並后的jar
1.將f:/target下面的 *.jar(M為單位) 上傳到服務器 執行 java -jar *.jar執行
二:源代碼和maven引入的包分離
1.第一次部署需要把lib整個文件夾,和*.original上傳,去掉original后綴 rename .original '' * 執行java -jar *.jar
2.后面每次修改了那個源代碼就只替換就行,新增了引入的jar也只需要上傳新增的jar到lib目錄中。
-->
<directory>/target</directory> <!--此處有坑-->
</build>
5、父子工程項目打包,父工程指定到統一目錄中。
<!-- 將子項目打包的copy到指定目錄--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>copy</id> <phase>package</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <!--把子項目target目錄下的jar拷貝到/target下--> <artifactItem> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> <type>${project.packaging}</type> <overWrite>true</overWrite> <!--copyTo的目錄--> <outputDirectory>/target</outputDirectory> </artifactItem> </artifactItems> </configuration> </execution> <!-- copy lib copy-dependencies copy依賴包--> <execution> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>/target/lib</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build>
