一.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>