spring boot maven构建及可执行jar包导出

在打包jar前执行:,将依赖导出至lib包,便于jar包依赖

mvn dependency:copy-dependencies  -DoutputDirectory=lib

在项目根目录下会自动生成一个lib目录
lib目录内容拷到target\lib目录中

mvn clean package
在maven Projects面板/sproutgis/Lifecycle/package生成两个文件
target\lib
target\sproutgis.jar
target\sproutgis-exec.jar

执行采用java -jar sproutgis-exec.jar
提示下面表示成功:

Tomcat started on port(s): 8888 (http)
Started app in 4.347 seconds (JVM running for 5.659)

maven配置pom.xml 关键部分

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <!-- 指定一下jdk的版本 ,这里我们使用jdk 1.8 ,默认是1.6 -->
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>1.3.5.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
<!-- spring boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <!--排除安全包 -->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-security</artifactId>
                </exclusion>
            </exclusions>
        </dependency>       
        <!-- spring boot devtools 依赖包. -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
            <scope>compile</scope>
        </dependency>
<plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>exec</id>
                            <phase>package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <configuration>
                                <classifier>exec</classifier>
                                <archive>
                                    <manifest>
                                        <mainClass>com.sapsoft.controller.app</mainClass>
                                        <addClasspath>true</addClasspath><!-- 添加依赖jar路径 -->
                                        <classpathPrefix>lib/</classpathPrefix>
                                    </manifest>
                                </archive>
                            </configuration>
                        </execution>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <configuration>
                                <!-- Need this to ensure application.properties is excluded -->
                                <forceCreation>true</forceCreation>
                                <excludes>
                                    <exclude>application.properties</exclude>
                                </excludes>
                                <archive>
                                    <manifest>
                                       <mainClass>com.sapsoft.controller.app</mainClass>
                                       <addClasspath>true</addClasspath><!-- 添加依赖jar路径 -->
                                       <classpathPrefix>lib/</classpathPrefix>
                                    </manifest>
                                </archive>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
<plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                          <goals>
                             <goal>repackage</goal>
                          </goals>
                        </execution>
                     </executions>
                    <configuration>
                        <classifier>exec</classifier>
                        <mainClass>com.sapsoft.controller.app</mainClass>
                        <!--layerout: JAR/WAR/ZIP/DIR/MODULE/NONE-->
                        <layout>NONE</layout>
                    </configuration>
                </plugin>
<repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

pom.xml全部文件内容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sapsoft</groupId>
    <artifactId>sproutgis</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <name>sproutgis</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <!-- 指定一下jdk的版本 ,这里我们使用jdk 1.8 ,默认是1.6 -->
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>1.3.5.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- 单元测试 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <!-- spring boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <!--排除安全包 -->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-security</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- 添加fastjson 依赖包. -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.15</version>
        </dependency>

        <!-- spring boot devtools 依赖包. -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.193</version>
        </dependency>
        <!-- ===spark=== -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>2.3.1</version>
        </dependency>
        <!-- ===geowave=== -->
        <dependency>
            <groupId>mil.nga.giat</groupId>
            <artifactId>geowave-analytic-spark</artifactId>
            <version>0.9.7</version>
        </dependency>
        <dependency>
            <groupId>mil.nga.giat</groupId>
            <artifactId>geowave-datastore-hbase</artifactId>
            <version>0.9.7</version>
        </dependency>
        <dependency>
            <groupId>mil.nga.giat</groupId>
            <artifactId>geowave-adapter-vector</artifactId>
            <version>0.9.7</version>
        </dependency>
        <!-- ===hadoop-client=== -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.7.4</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>sproutgis</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat9-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <port>8080</port>
                        <path>/</path>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                          <goals>
                             <goal>repackage</goal>
                          </goals>
                        </execution>
                     </executions>
                    <configuration>
                        <classifier>exec</classifier>
                        <mainClass>com.sapsoft.controller.app</mainClass>
                        <!--layerout: JAR/WAR/ZIP/DIR/MODULE/NONE-->
                        <layout>NONE</layout>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <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>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </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>
                    <artifactId>maven-jar-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>exec</id>
                            <phase>package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <configuration>
                                <classifier>exec</classifier>
                                <archive>
                                    <manifest>
                                        <mainClass>com.sapsoft.controller.app</mainClass>
                                        <addClasspath>true</addClasspath><!-- 添加依赖jar路径 -->
                                        <classpathPrefix>lib/</classpathPrefix>
                                    </manifest>
                                </archive>
                            </configuration>
                        </execution>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <configuration>
                                <!-- Need this to ensure application.properties is excluded -->
                                <forceCreation>true</forceCreation>
                                <excludes>
                                    <exclude>application.properties</exclude>
                                </excludes>
                                <archive>
                                    <manifest>
                                       <mainClass>com.sapsoft.controller.app</mainClass>
                                       <addClasspath>true</addClasspath><!-- 添加依赖jar路径 -->
                                       <classpathPrefix>lib/</classpathPrefix>
                                    </manifest>
                                </archive>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
    <distributionManagement>
        <repository>
            <id>nexus</id>
            <name>releases</name>
            <url>http://mvn2.qdingnet.com/nexus/content/repositories/releases</url>
            <uniqueVersion>true</uniqueVersion>
        </repository>
        <snapshotRepository>
            <id>nexus</id>
            <name>snapshots</name>
            <url>http://XXXXXXXXXXXXX/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>
</project>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值