使用宝塔发布springboot项目jar包保姆级详细教程


今天正好有空,就写个关于通过宝塔发布springboot项目的教程吧

  1. 首先在maven配置好发布环境
    <build>
            <finalName>jar-name</finalName>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <includeSystemScope>true</includeSystemScope>
                        <mainClass>com.xxx.xxx</mainClass>
                    </configuration>
                </plugin>
            </plugins>
        </build>
  2. 新建一个Linux部署环境的启动类,并且继承SpringBootServletInitializer类
    @SpringBootApplication(exclude = DataSourceAutoConfiguration.class,scanBasePackages={ "com.xxx.xxx"})
    public class DeployApplication extends SpringBootServletInitializer {
        public static void main(String[] args) {
            SpringApplication.run(DeployApplication.class, args);
        }
    
        /**
         * 为了打包springboot项目
         * @param builder
         * @return
         */
        @Override
        protected SpringApplicationBuilder configure(
                SpringApplicationBuilder builder) {
            return builder.sources(this.getClass());
        }
    }
    

      

  3. 打开宝塔界面,新建一个站点,并且绑定好域名

     

     

  4. 添加反向代理,将ip:端口发送到你的域名

     

     

  5. 将jar包放到这个站点指定的目录下面,然后通过宝塔打开终端或者使用SSH工具连接Linux
  6. 通过以下命令打开路径并进行发布
    cd /www/wwwroot/xxx
    java -jar xxx.jar
    

      

      

  7. 看到日志即发布成功

     

     

  8. 以下是后台运行的命令,log.file是运行的jar 错误日志信息输出到log.file文件中,然后(>&1)就是继续输出到标准输出(前面加的&,是为了让系统识别是标准输出),最后一个&,表示在后台运行。
    #使用外部yml配置文件
    nohup java -jar darcy-blog.jar --spring.config.location=application-pro.yml   > log.file  2>&1 &
    #不
    使用外部yml配置文件
    nohup java -jar darcy-blog.jar    > log.file  2>&1 &

      

  9. 最后就可以通过域名进行访问了

 

 

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM