如何处理IDEA无法识别maven镜像及下载jar包失败的问题?

2026-05-16 06:542阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计748个文字,预计阅读时间需要3分钟。

如何处理IDEA无法识别maven镜像及下载jar包失败的问题?

最近从公司私服下载jar包一直失败,之前的方法是手动下载项目,自己打包解决,但最近已无法忍受。原因在于idea当前版本要求maven的镜像必须是https的,而之前的配置并非如此。

最近从公司私服下载jar包一直失败,之前的解决方法是手动下载项目,自己打包来解决的,最近忍无可忍,自己研究了o(╥﹏╥)o.

原因

idea现在的版本要求maven的镜像必须是maven.aliyun.com/repository/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>huaweicloud</id> <mirrorOf>*</mirrorOf> <url>mirrors.huaweicloud.com/repository/maven/</url> </mirror>

再到默认的maven设置中为VM添加

如何处理IDEA无法识别maven镜像及下载jar包失败的问题?

-Dmaven.wagon.xxxxx/content/groups/public/</url> <!--私服地址--> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>

清理settings.xml中的镜像地址

不知道什么原因,虽然配置了上面的,但是我settings.xml的配置还会影响,必须将里面的自定义的镜像全部清理掉

此时刷新maven,就能从在pom配置的地址中下载依赖了

建议复制一个maven,里面的镜像库清理掉,需要下载http镜像的时候,就将maven选中这个,就不用专门去清理了

补充知识: 解决 Jackson反序列化 Unexpected token ... , expected VALUE_STRING: need JSON String that contains type id (for subtype of ...)

首先检查是否是 objectMapper.enableDefaultTyping(); 的受害者。优先考虑删除该配置。

使用Jackson把数组的json字符串反序列化为List时候报了个JsonMappingException。

java.lang.UnsupportedOperationException: com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (START_OBJECT), expected VALUE_STRING: need JSON String that contains type id (for subtype of java.util.List) at [Source: [ ......

找到问题代码,粗看似乎没什么问题?

List<MyObject> objectList = objectMapper.readValue(jsonString, new TypeReference<List<MyObject>>() {}); //jsonString是个json对象的数组

注意到异常信息“need JSON String that contains type id (for subtype of java.util.List)”。想了一会儿,好吧,有答案了。

List<MyObject> objectList = objectMapper.readValue(jsonString, new TypeReference<ArrayList<MyObject>>() {}); //jsonString是个json对象的数组

其实,有一种比较老派的反序列化为List的方式...

List<MyObject> objectList = Arrays.asList(objectMapper.readValue(jsonString, MyObject[].class)); //jsonString是个json对象的数组

当对一些较复杂的对象进行反序列化时,例如拥有接口类型成员变量的类。举个栗子:

@Data public class TypeValue { private Integer type; private List<Integer> value; }

有上面这个类,需要把json字符串反序列化成 Map<String, TypeValue> 这样的对象,怎么做?

可以在TypeValue这个类中使用 @JsonCreator 注解解决。

@Data public class TypeValue { private Integer type; private List<Integer> value; @JsonCreator //为Jackson提供构造函数 public TypeValue(@JsonProperty("type") final Integer type, @JsonProperty("value") final int[] value) { this.type= type; this.value = Ints.asList(value); } }

Jackson能够把[]数组转换为List。因此可以用以上方法绕过Jackson的限制。

以上使用了guava和lombok。

好了就介绍到这,希望能给大家一个参考,也希望大家多多支持易盾网络。

本文共计748个文字,预计阅读时间需要3分钟。

如何处理IDEA无法识别maven镜像及下载jar包失败的问题?

最近从公司私服下载jar包一直失败,之前的方法是手动下载项目,自己打包解决,但最近已无法忍受。原因在于idea当前版本要求maven的镜像必须是https的,而之前的配置并非如此。

最近从公司私服下载jar包一直失败,之前的解决方法是手动下载项目,自己打包来解决的,最近忍无可忍,自己研究了o(╥﹏╥)o.

原因

idea现在的版本要求maven的镜像必须是maven.aliyun.com/repository/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>huaweicloud</id> <mirrorOf>*</mirrorOf> <url>mirrors.huaweicloud.com/repository/maven/</url> </mirror>

再到默认的maven设置中为VM添加

如何处理IDEA无法识别maven镜像及下载jar包失败的问题?

-Dmaven.wagon.xxxxx/content/groups/public/</url> <!--私服地址--> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>

清理settings.xml中的镜像地址

不知道什么原因,虽然配置了上面的,但是我settings.xml的配置还会影响,必须将里面的自定义的镜像全部清理掉

此时刷新maven,就能从在pom配置的地址中下载依赖了

建议复制一个maven,里面的镜像库清理掉,需要下载http镜像的时候,就将maven选中这个,就不用专门去清理了

补充知识: 解决 Jackson反序列化 Unexpected token ... , expected VALUE_STRING: need JSON String that contains type id (for subtype of ...)

首先检查是否是 objectMapper.enableDefaultTyping(); 的受害者。优先考虑删除该配置。

使用Jackson把数组的json字符串反序列化为List时候报了个JsonMappingException。

java.lang.UnsupportedOperationException: com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (START_OBJECT), expected VALUE_STRING: need JSON String that contains type id (for subtype of java.util.List) at [Source: [ ......

找到问题代码,粗看似乎没什么问题?

List<MyObject> objectList = objectMapper.readValue(jsonString, new TypeReference<List<MyObject>>() {}); //jsonString是个json对象的数组

注意到异常信息“need JSON String that contains type id (for subtype of java.util.List)”。想了一会儿,好吧,有答案了。

List<MyObject> objectList = objectMapper.readValue(jsonString, new TypeReference<ArrayList<MyObject>>() {}); //jsonString是个json对象的数组

其实,有一种比较老派的反序列化为List的方式...

List<MyObject> objectList = Arrays.asList(objectMapper.readValue(jsonString, MyObject[].class)); //jsonString是个json对象的数组

当对一些较复杂的对象进行反序列化时,例如拥有接口类型成员变量的类。举个栗子:

@Data public class TypeValue { private Integer type; private List<Integer> value; }

有上面这个类,需要把json字符串反序列化成 Map<String, TypeValue> 这样的对象,怎么做?

可以在TypeValue这个类中使用 @JsonCreator 注解解决。

@Data public class TypeValue { private Integer type; private List<Integer> value; @JsonCreator //为Jackson提供构造函数 public TypeValue(@JsonProperty("type") final Integer type, @JsonProperty("value") final int[] value) { this.type= type; this.value = Ints.asList(value); } }

Jackson能够把[]数组转换为List。因此可以用以上方法绕过Jackson的限制。

以上使用了guava和lombok。

好了就介绍到这,希望能给大家一个参考,也希望大家多多支持易盾网络。