JDK:1.8.0_212

IDE:STS4(Spring Tool Suit4 Version: 4.3.2.RELEASE)

工程下载:https://files.cnblogs.com/files/xiandedanteng/SpringBootSample03_20190927_01.rar

如果不清楚如何做一个SringBoot工程请参考:https://www.cnblogs.com/xiandedanteng/p/11593880.html

SringBoot工程搭建完毕后,只需要再改动一下pom.xml,其目的是添加 executions节点,完整文件如下:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.hy</groupId>
    <artifactId>SpringBootSample03</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>SpringBootSample03</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>

                <!-- 特地为打包添加的节点,直接拷贝到你的文件的相应位置 -->
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <!-- 特地为打包添加的节点,直接拷贝到你的文件的相应位置 -->

            </plugin>
        </plugins>
    </build>

</project>

上面两行绿色汉字注释中间就是新增的节点。

之后,就是在工程中右键点击pom.xml,然后选择Run as ->Maven build...,点完了一个对话框会跳出来。

在Goals一项中填入package,然后点Run就行,STS4一顿忙活后,你要打的包在工程下的target目录下就出来了。

打开控制台,进去这个Jar文件所在的目录,然后输入 >java -jar SpringBootSample03-0.0.1-SNAPSHOT.jar

下面是执行效果

D:\>java -jar SpringBootSample03-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.8.RELEASE)

2019-09-27 10:53:42.009  INFO 4500 --- [           main] c.e.demo.SpringBootSample03Application   : Starting SpringBootSample03Application v0.0.1-SNAPSHOT on DESKTOP-8IDBHPK with PID 4500 (D:\SpringBootSample03-0.0.1-SNAPSHOT.jar started by horn1 in D:\)
2019-09-27 10:53:42.014  INFO 4500 --- [           main] c.e.demo.SpringBootSample03Application   : No active profile set, falling back to default profiles: default
2019-09-27 10:53:43.985  INFO 4500 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-09-27 10:53:44.032  INFO 4500 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-09-27 10:53:44.032  INFO 4500 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-27 10:53:44.195  INFO 4500 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-09-27 10:53:44.196  INFO 4500 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2093 ms
2019-09-27 10:53:44.538  INFO 4500 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-27 10:53:44.826  INFO 4500 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-09-27 10:53:44.831  INFO 4500 --- [           main] c.e.demo.SpringBootSample03Application   : Started SpringBootSample03Application in 3.467 seconds (JVM running for 4.014)
2019-09-27 10:53:55.285  INFO 4500 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-09-27 10:53:55.287  INFO 4500 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-09-27 10:53:55.302  INFO 4500 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 11 ms

然后,在浏览器输入:

http://localhost:8080/test

反馈会是:

欲戴王冠,必承其重

到这里,SpringBoot工程的Jar部署方式就ok了,它的效果和在STS4里Run java application一样。

网上同类文章对这种方式的具体操作方式五花八门,有繁琐有简单,还有些已经失去了时效。所以在参考时还得花点时间寻思鉴别一下,同时做实验验证,不能盲目照搬。

-- END -- 2019年9月27日11:15:12

最新文章

  1. [转]从网页Web上调用本地应用程序(.jar、.exe)的主流处理方法
  2. ThreadPool原理介绍
  3. memcached与.NET的融合使用(一)
  4. 关于jquery计算页面元素数量
  5. python的print(转)
  6. C# 制作外挂常用的API
  7. JUnit---Java单元测试必备工具
  8. python selenium自动化(三)Chrome Webdriver的兼容
  9. Codeforces Round #226 (Div. 2 )
  10. android学习日记10--裁剪区域
  11. CF 224 B Array
  12. hdu1495之经典搜索
  13. PIC16SCM设置不同IO功耗端口状态的影响
  14. When Hybrid Cloud Meets Flash Crowd: Towards Cost-Effective Service Provisioning--INFOCOM 2015
  15. spring框架应用系列一:annotation-config自动装配
  16. 浅谈MySQL的优化
  17. nginx解决跨域
  18. 详解在Linux下实现(彩色)进度条程序,并通过makefile进行编译.
  19. 翻译:非递归CTE(已提交到MariaDB官方手册)
  20. 【转】JS正则表达式大全(整理详细且实用)

热门文章

  1. vue+ckEditor5
  2. dhcpd.conf配置文件几例
  3. IPC之util.h源码解读
  4. imx6ull增加qt5 qtserialbus库
  5. 解决remix在线编译器连接本地私有链环境不成功的问题
  6. 深圳即将启动首届「全国人工智能大赛」:超过 500 万大奖 &amp; 政府资助,潜信息你读懂了吗!
  7. web添加学生信息(首发web)
  8. vue项目 WebViewJavascriptBridge 适配android和ios
  9. 03 深入远程执行:target目标、模块modules、返回returns
  10. 【agc004d】Teleporter