1、maven配置文件settings.xml设置
在项目1级目录下新建maven/settings.xml
settings.xml文件内容如下
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>aliyun</id>
<name>aliyun</name>
<mirrorOf>central</mirrorOf>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.login>admin</sonar.login>
<sonar.password>123456</sonar.password>
<sonar.host.url>http://192.168.12.110:9000</sonar.host.url>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>jdk18</activeProfile>
<activeProfile>sonar</activeProfile>
</activeProfiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
</settings>
引用settings.xml
-DarchetypeCatalog=internal
2、设置导出的jar包名称
3、编辑测试代码
如果出现如下错误,检测maven如上图所示的配置路径。并退出重新打开项目
java: 错误: 无效的源发行版:17
测试代码如下
package com.mydemo2.demo.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@GetMapping("/test")
public String test(){
return "hello mydemo2 !!!";
}
}
运行:运行–>新建配置–>左上角+号–>应用程序
4、导出为jar包
若不是第一次打包,先双击clean,后双击package
5、推送到gitlab中
在gitlab中新建仓库
复制ssh链接
配置idea
修改 .gitignore文件
修改内容为:target/ 修改为 target/**/
创建本地git仓库,略
添加远程仓库, git–管理远程–新建–添加ssh链接
推送–提交