Spring Boot Maven 打包可执行Jar文件!
2023-09-27 14:19:41 时间
Maven pom.xml 必须包含
- <packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <fork>true</fork>
- </configuration>
- </plugin>
- </plugins>
- </build>
完整pox.xml
- <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.feedback</groupId>
- <artifactId>feedback-service</artifactId>
- <version>0.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.3.0.RELEASE</version>
- </parent>
- <dependencies>
- <!-- spring boot -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-jpa</artifactId>
- </dependency>
- <!-- mysql数据库 -->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
- <!-- commons-lang -->
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.6</version>
- </dependency>
- </dependencies>
- <!-- jar -->
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <fork>true</fork>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </project>
进入到项目目录下运行:mvn clean package
会在项目目录下target文件夹中生成jar
如上生成的jar文件在:D:\programmer\eclipse\feedback-service\target 文件夹中
java -jar 运行jar包 即可
java -jar 运行jar包时使用外部配置文件application.properties
linux下执行jar
- nohup java -Xmx512M -Xms512M -Djava.security.egd=/dev/urandom -jar message-service-1.0-SNAPSHOT.jar > /dev/null 2>&1 &
Linux下还有一个特殊的文件/dev/null,它就像一个无底洞,所有重定向到它的信息都会消失得无影无踪。
>/dev/null 2>&1
注意:此处的顺序不能更改,否则达不到想要的效果,此时先将标准输出重定向到 /dev/null,然后将标准错误重定向到标准输出,由于标准输出已经重定向到了/dev/null,因此标准错误也会重定向到/dev/null,于是一切静悄悄:-)
相关文章
- 7 -- Spring的基本用法 -- 10... 获取其他Bean的属性值;获取Field值;获取任意方法的返回值
- Spring Tool Suite 使用自带maven速度慢---修改settings.xml更新mirror方法
- 深入实践Spring Boot1.2.1 使用Maven新建项目
- 《深入实践Spring Boot》一1.3 使用Spring Boot
- Spring mvc config
- Redis——maven、spring、jedis快速搭建redis工程
- Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.3.RELEASE:repac
- Spring boot 2.0 版本报错 ResourceHttpRequestHandler cannot be cast to HandlerMethod
- Spring事务失效的 8 大原因
- maven的java web项目启动找不到Spring ContextLoaderListener的解决办法
- maven+Spring环境搭建
- 五、Maven创建Spring(IDEA2019-3-3)
- spring boot 使用maven和fat jar/war运行应用程序的对比
- spring cloud学习地址
- Spring AOP 面向切面编程相关注解
- spring 配置文件 获取变量(PropertyPlaceholderConfigurer)
- Spring MVC与Dubbo的整合一
- Spring Boot—17MongoDB
- Spring和IDEA都不推荐用的@Autowired注解,为什么还有那么多人用?
- 用maven创建web项目(spring Mvc)
- [转载]架构指南 : Java1.7+Eclipse luna + Maven 3.2.5 +spring 4.1.4
- spring面试问题与答案集锦
- Descriptio Resource Path LocationType Archive for required library: 'D:/apache-maven/apache-maven-3.6.0/mavenrepository/org/springframework/spring-aspects/4.3.7.RELEASE/spring-aspects-4.3.7.RELEASE.
- spring mvc 绑定参数据默认值,是否必传,(RequestParam(value="id",defaultValue="1",required=true) )