Maven 使用笔记 (持续完善)

常用命令:
tomcat:run    tomcat运行项目
clean deploy   上传maven仓库

clean package  打包

clean install  安装jar

-Xms1024m -Xmx2024m -XX:MaxPermSize=256m

****************************************************************************************************************************
settings.xml 配置:
下载maven文件
地址: https://maven.apache.org/  找到下载链接
windows:
http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.zip


linux:
wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz 
apache-maven-3.5.3-bin.tar.gz


解压:
tar -zxvf apache-maven-3.5.3-bin.tar.gz


修改 settings.xml:


1,本地仓库地址:
<localRepository>E:\work_soft\maven\repository</localRepository>


2,远程仓库的认证
大部分公共的远程仓库无须认证就可以直接访问,但我们在平时的开发中往往会架设自己的Maven远程仓库,出于安全方面的考虑,
我们需要提供认证信息才能访问这样的远程仓库。配置认证信息和配置远程仓库不同,远程仓库可以直接在pom.xml中配置,
但是认证信息必须配置在settings.xml文件中。这是因为pom往往是被提交到代码仓库中供所有成员访问的,
而settings.xml一般只存在于本机。因此,在settings.xml中配置认证信息更为安全。
<servers>
<server>
      <id>junlenet</id>
      <username>admin</username>
      <password>junlenet_2020</password>
    </server>
</servers>
上面代码我们配置了一个id为releases的远程仓库认证信息。Maven使用settings.xml文件中的servers元素及其子元素server配置仓库认证信息。
认证用户名为admin,认证密码为admin123。这里的关键是id元素,settings.xml中server元素的id必须与pom.xml中需要认证的repository元素
的id完全一致。正是这个id将认证信息与仓库配置联系在了一起。




3,配置默认的jdk版本:(在eclipse中新建maven项目后的默认jdk版本)
在profiles节点里面新增:
<!-- 配置maven 项目 默认JDK为1.7 -->
<profile>
<id>dev-jdk1.7</id>
<activation>
 <jdk>1.7</jdk>
 <activeByDefault>true</activeByDefault>
</activation>
<properties>
 <maven.compiler.source>1.7</maven.compiler.source>
 <maven.compiler.target>1.7</maven.compiler.target>
 <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
</properties>
</profile>

4,配置远程仓库地址:
<profile>
<id>osc</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>osc</id>
<url>http://maven.oschina.net/content/groups/public/</url>
</repository>
<repository>
<id>osc_thirdparty</id>
<url>http://maven.oschina.net/content/repositories/thirdparty/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>osc</id>
<url>http://maven.oschina.net/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>




****************************************************************************************************************************
1,clean install 错误信息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project soa-user-api: Compilation failure: Compilation failure:
[ERROR] /D:/dubbo/soa-parent/soa-user/soa-user-api/src/test/java/com/junlenet/soa/user/api/AppTest.java:[3,23] 程序包junit.framework不存在
[ERROR] /D:/dubbo/soa-parent/soa-user/soa-user-api/src/test/java/com/junlenet/soa/user/api/AppTest.java:[4,23] 程序包junit.framework不存在
[ERROR] /D:/dubbo/soa-parent/soa-user/soa-user-api/src/test/java/com/junlenet/soa/user/api/AppTest.java:[5,23] 程序包junit.framework不存在
[ERROR] /D:/dubbo/soa-parent/soa-user/soa-user-api/src/test/java/com/junlenet/soa/user/api/AppTest.java:[11,13] 找不到符号
[ERROR] 符号: 类 TestCase
[ERROR] /D:/dubbo/soa-parent/soa-user/soa-user-api/src/test/java/com/junlenet/soa/user/api/AppTest.java:[26,19] 找不到符号
[ERROR] 符号:   类 Test
[ERROR] 位置: 类 com.junlenet.soa.user.api.AppTest
[ERROR] /D:/dubbo/soa-parent/soa-user/soa-user-api/src/test/java/com/junlenet/soa/user/api/AppTest.java:[28,20] 找不到符号
[ERROR] 符号:   类 TestSuite
[ERROR] 位置: 类 com.junlenet.soa.user.api.AppTest
[ERROR] /D:/dubbo/soa-parent/soa-user/soa-user-api/src/test/java/com/junlenet/soa/user/api/AppTest.java:[36,9] 找不到符号
[ERROR] 符号:   方法 assertTrue(boolean)
[ERROR] 位置: 类 com.junlenet.soa.user.api.AppTest
[ERROR] -> [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
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :soa-user-api


解决方案:
clean install -Dmaven.test.skip=true


****************************************************************************************************************************

解决maven下载jar失败后,无法下载.  本脚本是先清除下载失败的. 然后自己再修改一下pom.xml保存即可重新下载.     

操作:   新建一个cleanup.bat文件,把以下内容复制进去, 保存, 双击运行即可.

@echo off  
rem create by sunhao([email protected])  
rem crazy coder  
    
rem -- 这里写你的仓库路径  
set REPOSITORY_PATH=E:\work_soft\maven\repository
rem -- 正在搜索...  
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (  
    del /s /q %%i  
)  
rem 搜索完毕  

pause  

****************************************************************************************************************************

org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.MavenProject, org.apache.maven.archiver.MavenArchiveConfiguration) 

解决办法:Help——>Install New SoftWare -->> add 

MavenArchive

https://otto.takari.io/content/sites/m2e.extras/m2eclipse-mavenarchiver/0.17.2/N/LATEST/


安装完重启,再执行 maven-update project .

****************************************************************************************************************************



猜你喜欢

转载自blog.csdn.net/huweijun_2012/article/details/80236644
今日推荐