maven使用记录

1.使用maven打包项目时报错:[INFO] Using 'UTF-8' encoding to copy filtered resources.

有时候maven打包项目时会报这样的错:


[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.atguigu:springboot_02_config >------------------
[INFO] Building springboot_02_config 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ springboot_02_config ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 2 resources
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.679 s
[INFO] Finished at: 2021-07-27T13:54:22+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project springboot_02_config: Input length = 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

项目一直启动不了,很耽误时间。

 

解决方法:

===在springboot项目pom文件里的<build>标签里加上''maven-resources-plugin''插件,或者修改该插件的版本:===

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</build>

此时我使用的是2.6版本,只要不报错都可以,然后去Maven选项栏clean install一下,就能正常运行了。

 

2.maven项目修改源码时取消代码规范检查:

maven-checkstyle-plugin插件注释即可,注释掉后再编译项目还有可能有代码规范检查提示报错,根据报错提示,查看target文件中的PMD.xml错误日志文件,按照提示修改即可。

<!--            <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-checkstyle-plugin</artifactId>-->
<!-- <version>${maven-checkstyle-plugin.version}</version>-->
<!-- <configuration>-->
<!-- <configLocation>style/NacosCheckStyle.xml</configLocation>-->
<!-- <includeTestSourceDirectory>true</includeTestSourceDirectory>-->
<!-- <encoding>UTF-8</encoding>-->
<!-- <consoleOutput>true</consoleOutput>-->
<!-- <failsOnError>true</failsOnError>-->
<!-- <excludes>**/consistency/entity/**,**/nacos/test/**,**/api/grpc/auto/**,**/istio/**,**/protobuf/**</excludes>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>validate</id>-->
<!-- <phase>validate</phase>-->
<!-- <goals>-->
<!-- <goal>check</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->

 

3. nacos2.2.0版本源码编译时,maven报错提示:

参考原文链接:https://blog.csdn.net/wuchsh123/article/details/43970807
问题:程序包com.alibaba.nacos.consistency.entity不存在等错误,找不到类

原因:

  因为nacos 2.x 使用了grpc 作为底层通讯协议,这些对象都是以proto文件形式定义在proto文件夹中,需要我们使用maven插件手动编译成java class.

解决:

  针对这些编译错误一个一个来解决,这些编译错误都是【consistency】模块下的。右击consistency 项目下的pom.xml,选择 【Run Maven】 -> 【New Goal】 - 在【Command line】 输入【protobuf:compile】 命令,  点击ok。等待几分钟后. 再次运行【Nacos.java】我们发现还是会出现编译错误,但这次的编译错误都是在【istio】项目:

  我们采用上述同样的解决方法。右击【istio】项目下的pom.xml,选择 Run Maven -> New Goal - 在Command line 输入【protobuf:compile】 命令,  点击ok。等待几分钟后. 再次运行【Nacos.java】
此时还有可能报 istio.mcp.v1alpha1 包下面的某些类找不到, 右击项目【istio】项目下的pom.xml,选择 【Run Maven】 -> 【New Goal】 - 在Command line 输入【source:aggregate】 命令,  点击ok。 再次运行【Nacos.java】

4.项目编译时报错:You have 23 PMD violations. For more details see: C:\nacos-2.2.0\nacos-2.2.0\plugin\datasource\target\pmd.xml
 意思是:你有23条PMD违规。更多详细信息请看上面路径的文件内的说明。

   原因:一般都是因为编码不规范所触发的提示

           eg:注释缺少@author信息

 解决:按照要求完善格式即可

     eg:

/**
* .
* xxx
*
* @author ${USER}
* @date 2024-06-21
* Copyright © 2016 Cask Data, Inc.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

 5. maven项目再次打开莫名报知不到包或者类的错误

 eg: java.lang.NoClassDefFoundError: com/alibaba/nacos/common/utils/ResourceUtils

原因:可能是maven仓库内的jar包版本冲突导致,或者其他原因。

解决:① 首先尝试一些基础操作:比如clean、compile、install、重启刷新等。

   ② 还是不行的话可以找到maven仓库中的那个包,备份后删除,然后重新下载即可。

 

posted @   sensen~||^_^|||&  阅读(1465)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
点击右上角即可分享
微信分享提示