Spring Boot打包jar(包含本地包),指定main calss,并带参数调用

修改pom.xml的project里添加build节点

1. 指定 main class

  1)  添加 plugin,groupId:org.springframework.boot,atrifactId:a spring-boot-maven-plugin;

  2)  配置节点 build -> plugins -> plugin -> configuration -> mainlClass;

2. 包含本地包

  1)  添加 plugin,atrifactId:maven-complier-plugin;

  2)  配置节点 compilerArguments -> extdirs;

  3)  添加 resources -> resource节点;

  4)  配置相关节点 directory,targetPath,includes -> include;

  5)  如遇异常可将注释掉的 resource 节点启用(本人未遇到此问题)

 

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>org.badtree.Application</mainClass>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>  
                <target>1.8</target>  
                <encoding>UTF-8</encoding>
                <compilerArguments>
                    <!-- compiler local jars -->
                    <extdirs>${project.basedir}/lib/</extdirs>  
                </compilerArguments>
            </configuration>
        </plugin>
    </plugins>
    
    <!-- compiler local jars -->
    <resources>
        <resource>
            <directory>${project.basedir}/lib/</directory>
            <targetPath>/BOOT-INF/lib/</targetPath>  
            <includes>  
                <include>**/*.jar</include>  
            </includes>  
        </resource>
        <!--
        <resource>
            <directory>src/main/resources</directory>
            <targetPath>BOOT-INF/classes/</targetPath>
        </resource>
         -->
    </resources>
</build>

 

运行 jar

1. 普通运行

java -jar badtree-0.0.1-Release.jar

 

2. 带参数运行

java -jar -Dpassword=123546 badtree-0.0.1-Release.jar

 

3. 设置本地配置文件(不使用 jar 内的 application.properties),并带参数运行

java -jar -Dspring.config.location=application.properties -Dpassword=123456 badtree-0.0.1-Release.jar

 

posted on 2018-06-06 16:17  BadTree  阅读(1509)  评论(0编辑  收藏  举报