Maven常见问题总结(持续更新)

一、archetype:create-from-project制作自己的目录结构(自定义Archetype)

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:create-from-project (default-cli) on project 01-Test: ${maven.home} is not specified as a directory: 'D:\MyEclipse\WorkSpaces\SpringCloud\01-Test\EMBEDDED'. -> [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/MojoFailureException

问题原因:利用了IDE(Eclipse/IDEA)自带的Maven。
因为不能上传图片,引用别人的

这里引用别人的图片
如果以上设置后,对于高版本的Maven,则有可能会提示找不到mvn.bat文件:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:create-from-project (default-cli) on project 01-Test: Error configuring command-line. Reason: Maven executable not found at: C:\maven\apache-maven-3.5.4\bin\mvn.bat -> [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/MojoFailureException

只需要在bin目录下将“mvn.cmd”复制一份,并更名为:“mvc.bat”。
以上是生成Archetype。可以继续安装到本地仓库以供其他项目使用install,也可以上传至团队公共的私服仓库deploy。

二、Maven工程,不显示源文件包

有时候Eclipse/IDEA会出现在src/mian/java等目录显示异常情况,这是IDE的本身的问题,是IDE刷新目录时没有正常显示的原因。
解决方案:
1、手动修改classpath文件

此方法不仅仅适用于Maven项目,对于所有的项目都是一样的,因为IDE就是解析该文件显示目录结构的。
2、在项目上右键选择properties,然后点击java build path,在Librarys下,编辑JRE System Library,选择workspace default jre就可以了。
3、重启IDE软件。

三、Problems窗口中显示:maven missing artifact

往往是由于不能从仓库中下载相应的依赖造成的,国内最好配置阿里云仓库地址:

<mirror>
	<id>nexus-aliyun</id>
	<mirrorOf>*</mirrorOf>
	<name>Nexus aliyun</name>
	<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

可以配置多个mirror。

四、package Explorer视图下工程中图标有小红叉、但工程下的文件没有显示红叉

这种情况下,如果问题没有在problem窗口中显示,往往就需要:
选中项目:右键项目 > Maven > Update Project Configuration
五、Maven本地仓库中的jar包名字后有lastUpdate
原因:maven从nexsu上面拉jar包,有时会因为网络问题导致下不了包,这时候文件夹内会个*lastUpdated.properties的文件,而这文件的存在会导致下次服务器不会去下载这个包,这时候要删掉这个文件才能让maven再次去下载。(可以用批处理命令进行清理)

windows:del /f /s /q D:\Maven\Test*.lastUpdated
linux:*find ./ -name “lastUpdated” | xargs -i -t rm {} -rf

猜你喜欢

转载自blog.csdn.net/huxiutao/article/details/86009055
今日推荐