使用IDEA创建Java7的Spring Boot项目
1、创建项目:
在IDEA中正常创建SpringBoot项目,无法直接创建Java7 的项目。
创建中即使SDK选择的是1.7,但仍无法选择Java:7
那么只能先正常创建Java8的Spring Boot项目了。
2、修改项目参数
修改基本集中于pom文件和IDEA的配置
1、pom.xml
修改Spring Boot的版本:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath/>
</parent>
添加Java版本申明:
<properties>
<java.version>1.7</java.version>
</properties>
打包版本申明:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
显式的引入第三方库
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/commons-collections-3.2.1.jar</systemPath>
</dependency>
2、IDEA的配置
需修改五个地方
3、调用测试
0、编写测试用例
显式的引入第三方包:
package com.dyaqi.jave7runspringbootdemo.controller;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.ListUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
* @author: dongyq
* @date: 2022/5/18 11:14
* @since:
* @功能描述:
*/
@RestController
@RequestMapping
public class Controller {
/**
* 测试显式引入第三方库(commons-collections-3.2.1.jar在lib中引入)
* @return
*/
@RequestMapping(value = "/to", method = {RequestMethod.GET})
public String to() {
List<Integer> t_list = new ArrayList();
t_list.add(1);
boolean t_empty = CollectionUtils.isEmpty(t_list);
System.out.println(t_empty);
return t_empty ? "empty" : "not empty";
}
}
1、IDEA中启动测试
调用打印:
控制台打印:
启动调用OK!
2、打jar包测试
打包:
打开项目所在的target
文件,使用以下命令启动项目:
java -jar .\Jave7RunSpringBootDemo-0.0.1-SNAPSHOT.jar
调用打印:
控制台打印:
启动调用OK!
4、可能出现的问题及解决方案
.\Jave7RunSpringBootDemo-0.0.1-SNAPSHOT.jar中没有主清单属性
此时需要在pom.xml中加入:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
分类:
IDEA使用
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义