IntelliJ IDEA下spring boot项目打包
Posted 逆水行舟,不进则退
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IntelliJ IDEA下spring boot项目打包相关的知识,希望对你有一定的参考价值。
Spring Boot自带Tomcat插件,可以直接编写启动类,开启Tomcat服务
springboot适合前后端分离,打成jar进行部署更合适
application.properties配置端口
server.port=8089
marven的配置文件pom.xml
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.company</groupId> <artifactId>project</artifactId> <version>1.0</version> <packaging>jar</packaging> <properties> <java.version>1.8</java.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.13.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> …… </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> <repositories> <repository> <id>aliyun-repos</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>aliyun-plugin</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </project>
注:
如果打jar的时候会说找不到主类,build那部分修改下
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.company.project.Application</mainClass> </configuration> </plugin> </plugins> </build>
启动类修改下
package com.company.project; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } //为了打包springboot项目 protected SpringApplicationBuilder configure( SpringApplicationBuilder builder) { return builder.sources(this.getClass()); } }
按照顺序运行mvn clean再mvn install
我们需要的jar就打好包了
到这个目录下执行命令
java -jar project-1.0.jar
以上是关于IntelliJ IDEA下spring boot项目打包的主要内容,如果未能解决你的问题,请参考以下文章
IntelliJ IDEA打开Maven项目,Spring boot所有依赖红名,不可用
intellij idea 怎么找不到spring boot
使用IntelliJ IDEA创建Spring Boot项目
Intellij IDEA 设置Spring Boot热部署