`
sundful
  • 浏览: 1232491 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

maven一些问题

 
阅读更多

1. The container 'Maven Dependencies' references non existing library

解决方法,将eclipse中maven插件中“resolve dependencies from workspace projects”的选项取消
 
默认的本地库更改,修改maven_home\conf\settings.xml中localRepository的配置
 
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (...). Please verify you invoked Maven from the correct directory. 
到有pom.xml文件的目录下执行命令

 

 
2.      myeclipse从svn导入maven项目,有modules。
myeclipse的check out maven projects from scm,没有试成功怎么导出。但可以先从svn检查maven项目,包含子module,然后再导入exists maven projects。

 

3. Failure to find xxx:jar:1.0 in ... was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced
      这是一些jar包在之前的仓库无法获得,在更改仓库后,或把jar包部署到了私服上后,仍然出错。这时把.m2 文件夹下对应的 xxx.lastUpdated文件再更新依赖,就可以了。或者使用mvn命令时加 -U参数,忽略xxx.lastUpdated。

      另外以上方式仍然报错,这时可能是maven 库或私服里确实没有对应的jar包,这时可以在私服里增加仓库,或者更改仓库。

 

4.      pom聚合的install,在maven 的build config里,goals选项里填入install,profiles中填入maven聚合项目中配置的modules profile的id,如果是如下配置:
<profiles>
  
  <profile>
    <id>modules</id>
    <modules>
<module>modules/parent</module>
<module>modules/common</module>
<module>modules/entity</module>
<module>modules/ejb</module>
<module>modules/spring</module>
<module>modules/hibernate</module>
<module>modules/web</module>
<module>modules/test</module>
  </modules>
  </profile>
</profiles>
则这里就要填入modules

 

5.  maven install的plugin找不到,比如effective pom 中配的是2.3.1,本机上已经有2.2.1了,是不会使用的。就会去maven仓库中下载新版本,maven 的中央库连接经常不稳定。一般会在settings.xml中配置一些镜像。但maven不会依次去尝试所有镜像,而当排在前面的镜像失效、或不能提供最新版本时,就需要调整镜像的位置。

 

6.  导入的maven项目找不到jdk中的类
jdk版本是1.6,ide是ide出问题了,将Myeclipse重启ide,对有依赖的maven项目进行更新maven依赖、更新maven项目配置操作,然后对本项目clean、 重新build后就可以了。

 

7.  拷贝依赖包 mvn dependency:copy-dependencies,默认会拷到项目的 target\dependency 目录,想要复制到自定义的目录比如target/libs目录下,需要在pom.xml文件中添加设置覆盖默认设置:
<build> 
    <plugins> 
        <plugin> 
            <artifactId>maven-dependency-plugin</artifactId> 
            <configuration> 
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                <excludeTransitive>false</excludeTransitive> 
                <stripVersion>true</stripVersion> 
            </configuration> 
        </plugin> 
其中${project.build.directory}是maven变量,表示target目录。如果不写的话,将在根目录下创建lib目录。
excludeTransitive,表示是否不包含间接依赖的包;
stripVersion表示复制的jar文件去掉版本信息。
如果需要在其他过程,比如package中加入copy-dependencies,需要在该plugin标签中这样设置:
 
<executions> 
    <execution> 
        <id>copy-dependencies</id> 
        <phase>package</phase> 
        <goals> 
            <goal>copy-dependencies</goal> 
        </goals> 
        <configuration> 
            <outputDirectory>libs</outputDirectory> 
            <excludeTransitive>false</excludeTransitive> 
            <stripVersion>true</stripVersion> 
        </configuration> 
    </execution> 
</executions>

 

8. 导入jar包到本地库
      有时候有些第三方就是从仓库中下载不下来,配的私服也有问题,就只有手动导入jar包了。Myeclipse 10 可以使用“Myeclipse -- utilities -- Maven4MyEclipse -- import jar to local repository”工具,导入jar包到本地库。eclipse的m2eclipse插件暂时没找到这样的工具。使用maven命令的可以这样:
mvn install:install-file 
-DgroupId=com.danga 
-DartifactId=memcached 
-Dversion=2.0.1 
-Dfile=java_memcached-release_2.0.1.jar (或者/d:/java_memcached-release_2.0.1.jar)
-Dpackaging=jar -DgeneratePom=true
This will add the memcache jar into your local Maven2 repository under groupId com.danga and artifactId memcached, you can then edit your pom.xml adding this dependency.
 
However, the maven eclipse can not recognize it since it always search from public repository .
 
安装到私服
    mvn deploy:deploy-file -DgroupId=org.apache.hadoop  -DartifactId=hbase -Dversion=1.0 -Dpackaging=jar -Dfile=[path to file] -Durl=[url] -DrepositoryId=[id]
 
批量导入jar
    直接拷贝文件至/opt/data/nexus/sonatype-work/nexus/storage/pvinsight/org/apache/hadoop/hive/hive-exec/0.5.0
    或者
    通过脚本执行 mvn deploy:deploy-file  

 

9. 使用maven发布是,报某个类找不到,原因是某个运行时的类,import了用于测试的类(但并未使用),比如junit相关的类。这样,在ide中和maven compile时都不会报错,在打包时,由于junit这样的jar的scope是test类型,因此就不会包含进来,于是就出错了。解决方法就是删除不不要的引用。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics