学习Maven过程中出现的错误

以下均为学习Maven和私服过程中出现的bug

maven:编译出现Process terminated解决方法(超全)

前言

一般出现这种错误,主要讲解常见的错误提示以及如何通过错误指示找到正确的解决方法
maven插件中编译执行测试等都出现Process terminated
如图所示:

解决方式是点击项目中的提示看清楚具体错误在哪里,本错误点开项目之后出现的错误是找不到xml文件,需要正确导入即可

  1. xml文件找不到
    一般解决bug都要从根源找到,这也是给每个浏览我的博客的人一个启发
    因为不一定你的根源和我的一样

找到根源的解决方法
点击项目文件,会出现提示,暗示xml文件找不到,需要导入xml文件

需要在setting设置中的maven中正确导入xml文件以及库文件等信息,且版本以及库是否选择对应正确

勾选正确之后,重新clean以及compile等即可成功

  1. 项目名配对
    和上一个思路一样,也是找到根源
    通过找到其问题所在,在逐一攻破
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'artifactId' with value '11.1 springmvc' does not match a valid id pattern. @ line 8, column 17 @ 
[ERROR] The build could not read 1 project -> [Help 1]

找到问题所在,将其名字更改为一样的,且不能带空格

之后编译就成功了

  1. 其他
    另一种错误提示:
    如果点开项目中,提示xml文件没对齐,需要在xml文件中对齐文件格式,因为xml文件格式没对齐,即使导入正确了,也会编译执行不了

如果对齐还编译出错
看看配置文件中的配置信息有无出错
比如jdk版本
名字 组id等
类似这种信息

maven打包出错:There are test failures

在用maven进行打包的时候出现错误

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project yuyun: There are test failures.

Please refer to E:\IdeaProjects\yuyun\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
在其他地方搜到很多,都是跳过Test打包

然后我在命令行用命令mvn clean package打包,发现在测试类出现错误
![](https://img2023.cnblogs.com/blog/2549455/202212/2549455-20221204232721294-676902284.png)

之后我去查看测试类的代码

package com.example.yuyun;

import com.example.yuyun.model.Users;
import com.example.yuyun.security.utils.SecurityUtils;
import com.example.yuyun.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class YuyunApplicationTests {

@Autowired
UserService userService;

@Test
void contextLoads() {
    Users users=userService.getUser("91");
    for (int i=0;i<100;i++){
        users.setUserName("用户1"+i);
        users.setUserPwd(SecurityUtils.encodePassword(String.valueOf(458246+i)));
        Boolean u=userService.insertUsers(users);
    }
}

}

将里面的功能代码注释掉,重新打包就没有问题了
![](https://img2023.cnblogs.com/blog/2549455/202212/2549455-20221204232757685-665887151.png)

## Failed to transfer file http://localhost:8081/repository/heima-release/com/hcx
Failed to transfer file http://localhost:8081/repository/heima-release/com/itheima/springMVC_test3/1.0-SNAPSHOT/maven-metadata.xml with status code 400
​ 今天我写了一个maven项目,想用上传的方式把自己写的war包载入私服里面,这里用到Nexus上传的时候出现以下的错误如图

![](https://img2023.cnblogs.com/blog/2549455/202212/2549455-20221204233231584-1472492328.png)


下面是我的发布的版本号

![](https://img2023.cnblogs.com/blog/2549455/202212/2549455-20221204233241728-1645609005.png)


​ 下面是我要上传的资源配置(注意我画的地方这里我用的maven2_hosted类型的库且为release发布版)

![](https://img2023.cnblogs.com/blog/2549455/202212/2549455-20221204233253090-927507257.png)


后来经过手动上传war包时发现的这个错误

如下
![](https://img2023.cnblogs.com/blog/2549455/202212/2549455-20221204233304149-1285093332.png)



当我点击上传时,Nexus自动提示输入的版本有错误,所以Nexus还是比较智能的,从而导致无法上传

错误原因:版本出现错误

正确操作:将SNAPTION改为RELEASE再次上传
![](https://img2023.cnblogs.com/blog/2549455/202212/2549455-20221204233404523-835408859.png)



此处不变
![](https://img2023.cnblogs.com/blog/2549455/202212/2549455-20221204233419510-648975334.png)



接着deploy

![](https://img2023.cnblogs.com/blog/2549455/202212/2549455-20221204233431027-184162935.png)


上传成功!!!

总结:一定要注意上传私服的版本号
posted @ 2022-12-04 23:35  筝弈  阅读(85)  评论(0编辑  收藏  举报
2 3
4