pom文件中添加了“org.springframework.boot:spring-boot-maven-plugin”插件。在添加了该插件之后,当运行“mvn package”进行打包时,会打包成一个可以直接运行的 JAR 文件,使用“java -jar”命令就可以直接运行。

可以在POM中,指定生成 的是Jar还是War <packaging>jar</packaging> 默认为jar

你还可以指定要执行的类,如果不指定的话,Spring会找有这个public static void main(String[] args)方法的类,当做可执行的类。当出现两个类含有main方法时,会报错。

可以通过以下两个方法来指定启动类:

第一种:如果你的POM是继承spring-boot-starter-parent的话,只需要下面的指定就行

  1. <properties>
  2. <!-- The main class to start by executing java -jar -->
  3. <start-class>com.xx.xx</start-class>
  4. </properties>

第二种:如果你的POM不是继承spring-boot-starter-parent的话,需要下面的指定

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.springframework.boot</groupId>
  5.           <artifactId>spring-boot-maven-plugin</artifactId>
  6.          <version>1.3.5.RELEASE</version>
  7.          <configuration>
  8.             <mainClass>com.xx.xx</mainClass>
  9.          </configuration>
  10.           <executions>
  11.             <execution>
  12.             <goals>
  13.             <goal>repackage</goal>
  14.             </goals>
  15.             </execution>
  16.          </executions>
  17. </plugin>
  18. </plugins>
  19. </build>

打包如果没有将配置文件加载进去或者有些系统,关于一些数据库或其它第三方账户等信息,由于安全问题,其配置并不会提前配置在项目中暴露给开发者。对于这样的情况,我们在运行程序的时候。能够通过參数指定一个外部配置文件。

<span style="font-family:SimSun;font-size:16px;">java -jar xx.jar --spring.config.location=application.properties</span>

spring-boot-maven-plugin 插件的作用的更多相关文章

  1. Spring Boot Maven Plugin(二):run目标

    简介 Spring Boot Maven Plugin插件提供spring boot在maven中的支持.允许你打包可运行的jar包或war包. 插件提供了几个maven目标和Spring Boot ...

  2. Spring Boot Maven Plugin(一):repackage目标

    简介 Spring Boot Maven Plugin插件提供spring boot在maven中的支持.允许你打包可运行的jar包或war包. 插件提供了几个maven目标和Spring Boot ...

  3. Spring Boot的Maven插件Spring Boot Maven plugin详解

    Spring Boot的Maven插件(Spring Boot Maven plugin)能够以Maven的方式为应用提供Spring Boot的支持,即为Spring Boot应用提供了执行Mave ...

  4. Spring Boot Maven Plugin打包异常及三种解决方法:Unable to find main class

    [背景]spring-boot项目,打包成可执行jar,项目内有两个带有main方法的类并且都使用了@SpringBootApplication注解(或者另一种情形:你有两个main方法并且所在类都没 ...

  5. 微服务下 Spring Boot Maven 工程依赖关系管理

    单体 Spring Boot Maven 工程 最基本的 pom.xml 包含工程信息.Spring Boot 父工程.属性配置.依赖包.构建插件 <?xml version="1.0 ...

  6. SpringBoot 之Spring Boot Starter依赖包及作用

    Spring Boot 之Spring Boot Starter依赖包及作用 spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. spri ...

  7. spring boot集成mybatis-plus插件进行自定义sql方法开发时报nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    spring boot集成mybatis-plus插件进行自定义sql方法开发时报nested exception is org.apache.ibatis.binding.BindingExcept ...

  8. spring boot maven META-INF/MAINIFEST.MF

    unzip -p charles.jar META-INF/MANIFEST.MF https://blog.csdn.net/isea533/article/details/50278205 htt ...

  9. spring boot maven打包可运行jar包

    普通打包之后在程序目录运行,或者编写bat运行时会提示“没有主清单属性”,这是因为并没有找到main()方法,需要我们指明告诉java程序 我bat中的代码 @echo off title mytit ...

  10. Spring boot+ maven + thymeleaf + HTML 实现简单的web项目

    第一步: 创建一个SpringBoot应用 第二步: 创建一个实体,用来存储数据,在src/main/java/com/example/first下创建包entity , 在entity下创建Pers ...

随机推荐

  1. fedora 修改home下的中文目录为英文目录

    <h4>修改home下的中文目录为英文目录</h4>习 惯问题,喜欢使用fedora为您在home目录下自创建的“桌面”.“文档”,“图片 .公共的” .“下载”. “音乐”. ...

  2. 可能是 BJOI2019 Day1 题解?

    T1 给一个有空白字符的串 $S$,和若干模板串 $X_i$,初始 $Ans = 1$,每当一个模板串在 $S$ 中作为子串出现时,$Ans$ 会乘以 $X_i$ 的权值 $Val_i$,然后如果 $ ...

  3. 自己理解的java工厂模式,希望对大家有所帮助

    [http://www.360doc.com/content/11/0824/17/3034429_142983837.shtml] 这两天突然想学学java源代码,不过看到一篇文章说看java源代码 ...

  4. POJ3422 Kaka's Matrix Travels 【费用流】*

    POJ3422 Kaka's Matrix Travels Description On an N × N chessboard with a non-negative number in each ...

  5. selenium python实例脚本1

    #!/usr/local/bin/python3 # coding=utf-8 #统一编码from selenium import webdriverfrom time import sleep#im ...

  6. Working out

    Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the ...

  7. flask第七篇——URL与视图函数的映射

    有兴趣的朋友可以添加微信公众号:自动化测试实战 今天开始就要进入正题了.大家都准备好了吧~ 代码提示 先和大家说个小知识点:有同学后台说输入flask代码pycharm不提示,现在告诉你一个解决方法: ...

  8. tomcat  nginx  证书切换

    1. 导出公钥 keytool -export -alias tomcat -keystore <you jks>wsriakey.keystore -file <outputfil ...

  9. caddy server 了解

    Caddy 是一个Go写的服务器软件,官方的宣传语“The HTTP/2 web server with automatic HTTPS”以及“Serve The Web Like It's 2016 ...

  10. centos7下安装docker 17.x

    docker的17.X版本与以前的docker安装有些不同,参考了下这篇文章http://www.itmuch.com/docker/docker-2/,以下是我的docker 17.X版本安装过程, ...