maven

1、用mvn compile编译代码,出现错误:[ERROR] error: error reading 。。。error in opening zip file

原因及解决办法:由于maven下载了空的或者不完全的jar包在仓库中,删除之后让maven重新下载

2、把依赖的jar包复制到target目录的dependency子目录

mvn dependency:copy-dependencies


见http://tianya23.blog.51cto.com/1081650/289363

3、maven打包自动添加main class
在pom.xml文件中添加如下内容:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix></classpathPrefix>
<mainClass>MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>


4、maven忽略测试阶段
-Dmaven.test.skip=true


5、maven migration插件创建新脚本命令
mvn migration:new


6、maven migration插件指定脚本生成路径
-Dmigration.path=your/path


7、maven migration插件指定脚本描述文字
-Dmigration.description="your description"


8、maven修改模块的版本号
mvn versions:set -DnewVersion=版本号


会生成原来版本号的备份文件

mvn versions:commit # 使用新的版本号,删除备份文件


mvn versions:revert # 回退成老的版本号,删除备份文件


9、查看maven依赖树命令
mvn dependency:tree


10、maven库中jar存在,但无法依赖jar的问题
intellij中reimport也无法解决,是因为在maven库jar包目录中存在.lastUpdated文件,造成maven不下载jar文件也不解决依赖问题,只能把.lastUpdated文件删除,或者使用-U选项,如
mvn compile -U


11、指定仓库
<repositories>
<repository>
<id>nexus</id>
<name>依赖包仓库</name>
<url>http://host:8080/content/repositories/central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>依赖插件包仓库</name>
<url>http://host:8080/content/repositories/central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>


12、把依赖jar文件的class打入jar包
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix></classpathPrefix>
<mainClass>MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>

然后用命令
mvn assembly:assembly
打包

13、maven-compiler-plugin 指定编译器版本和编码

            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>


14、安装jar包到本地maven仓库

mvn install:install-file -DgroupId=groupId -DartifactId=artifactId -Dversion=版本号 -Dpackaging=jar -Dfile=jar文件路径
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值