SpringBoot项目在Eclipse中实现打包发布

场景

项目搭建专栏:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/35688

实现

首先设置打包的方式,这里设置为war包。

找到pom.xml

SpringBoot项目在Eclipse中实现打包发布_第1张图片

修改打包时的项目依赖的tomcat,使其在编译运行时使用tomcat,打包时不需要将tomcat打进包中


  
   org.springframework.boot
   spring-boot-starter-tomcat
   provided
  

找到项目的启动类,使其继承SpringBootServletInitializer并重写方法configure来指定项目启动类。

SpringBoot项目在Eclipse中实现打包发布_第2张图片

package com.example.demo;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
@MapperScan("com.example.demo.mapper")
@EnableScheduling
@SpringBootApplication(scanBasePackages= {"com.example.demo.controller","com.example.demo.service","com.example.demo.interceptor","com.example.demo.handler","com.example.demo.job","com.example.demo.email"})
public class HelloSpringBootApplication extends SpringBootServletInitializer{
{



 @Override
 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
 
  //指明启动类
  return builder.sources(HelloSpringBootApplication.class);
 }

  public static void main(String[] args) {
  
  SpringApplication.run(HelloSpringBootApplication.class, args);
 }

}

右键项目--run as --Maven build

SpringBoot项目在Eclipse中实现打包发布_第3张图片

输入命令 clean package,然后点击Run

SpringBoot项目在Eclipse中实现打包发布_第4张图片

打包成功

SpringBoot项目在Eclipse中实现打包发布_第5张图片

来到项目的target目录下,可以看到打包后的war包。

SpringBoot项目在Eclipse中实现打包发布_第6张图片

如果打包时出现提示:

Perhaps you are running on a JRE rather than a JDK?

参照:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/89323530

 

源码下载

https://download.csdn.net/download/badao_liumang_qizhi/11117994

你可能感兴趣的:(SpringBoot,SpringBoot实战项目)