欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Springboot打包成jar發(fā)布的操作方法

 更新時(shí)間:2023年02月28日 14:30:33   作者:weixin_45914112  
打包的方式有打包成jar包或者打包成war包發(fā)布,區(qū)別在于jar包內(nèi)置了tomcat、netty等服務(wù)器,更改只需要修改pom.xml的坐標(biāo)即可,war不內(nèi)置服務(wù)器,需要上傳到服務(wù)器tomcat解壓后運(yùn)行,本文分析Springboot打包成jar發(fā)布,感興趣的朋友一起看看吧

打包的方式

  • 打包成jar包
  • 打包成war包
    區(qū)別:jar包內(nèi)置了tomcat、netty等服務(wù)器,更改只需要修改pom.xml的坐標(biāo)即可,war不內(nèi)置服務(wù)器,需要上傳到服務(wù)器tomcat解壓后運(yùn)行

如何打包?

1.打包成jar,pom.xml中設(shè)置打包的形式,war/jar包

 <packaging>jar</packaging>

2.添加maven打包插件

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

1.正常情況下,IDEA右側(cè)點(diǎn)擊Maven----》clean-----》package即可打包成功。

所遇到的問(wèn)題,及解決辦法

  • 提示要設(shè)置UTF-8 編碼,主要是編碼格式不對(duì)。
  • maven版本過(guò)高
  • 沒(méi)有把項(xiàng)目resource文件的配置文件以及XML文件一起打包
    然后就會(huì)出現(xiàn)以下問(wèn)題。---------------------》
Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project bookshop: Input length = 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

解決辦法

1、設(shè)置IDEA的項(xiàng)目編碼格式為UTF-8

如果不行,就在pom.xml中添加以下配置:

 <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 </properties>
     <!--  跟 <dependencies>同級(jí)-->

2.maven版本過(guò)高,降低maven版本

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.0.2</version>
</plugin>

3.如果配置了上面的依舊不行,,,那就一定要配置下面這個(gè),主要是把resource文件配置,一起打包到j(luò)ar包里。(我就是上面兩部都不行,配置了這個(gè)就好了)
在pom.xml中配置

  <resources>
            <!--把java下的.xml和properties文件編譯打包-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
        <!-- </resources>  跟   </plugins> 同級(jí),都是在<build>標(biāo)簽內(nèi)-->

結(jié)果(此時(shí),再次IDEA右側(cè)點(diǎn)擊Maven----》clean-----》package即可打包成功)

這里就是我們辛辛苦苦打包出來(lái)的jar包了

如何運(yùn)行它呢?

沒(méi)錯(cuò),就是它-----》target 目錄下 打開控制臺(tái) 使用命令 java -jar bookshop-0.0.1-SNAPSHOT.jar 就可以起來(lái)了。如果要發(fā)布到服務(wù)器,使用云端數(shù)據(jù),那你要配置數(shù)據(jù)庫(kù)文件的IP、端口、賬號(hào)、密碼、連接方式(尤其要降低mysql版本或者升高版本的要特別注意)

看看效果

到這里終于完成了。如果熟悉linux的話可以發(fā)布到linux

關(guān)于運(yùn)行命令的話可以去了解相關(guān)的命令

nohup java -jar xxx.jar &
java -jar xxx.jar 
java -jar xxx.jar &

到此這篇關(guān)于Springboot打包成jar發(fā)布的操作方法的文章就介紹到這了,更多相關(guān)Springboot打包成jar發(fā)布內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論