maven一些问题 - ljhzzyx的日志 - 网易博客

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类型,因此就不会包含进来,于是就出错了。解决方法就是删除不不要的引用。
10. 使用mvn compile命令,出现
错误: 编码GBK的不可映射字符
不能编译。这是因为代码或注释中存在中文引起的,一般在ide中会自动处理编译时的字符集,就不会碰到这个错误。这个错误是在生成代码后,其中自动加上了中文注释,手动删除中文注释处理这个问题太麻烦。这个错误是在命令行执行编译命令才出现的,需要设置编译的字符集,设置方式是:
maven编译文件的编码设置如下:
<plugin> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <encoding>UTF-8</encoding> 
    </configuration> 
</plugin> 
<encoding>UTF-8</encoding>,如果不设置的话会用本地操作系统的编码来编译文件。
资源文件的编码设置如下:
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-resources-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
        <encoding>UTF-8</encoding> 
    </configuration> 
</plugin>
设置好maven-compiler-plugin编码再运行mvn compile就没有这个错误了。
11. maven打包时,SNAPSHOT类型的依赖包,会加上时间戳,像下面这样
xxx-1.3.0-20121225.012733.jar
如果不想用时间戳,始终使用SNAPSHOT,xxx-1.3.0-SNAPSHOT.jar这样的,需要使用<useUniqueVersions>false</useUniqueVersions>配置。在assemble插件里有描述:http://maven.apache.org/shared/maven-archiver/examples/classpath.html。而有完整例子的在这个日文网站http://kenichiro22.hatenablog.com/entry/20110908/1315481232
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.xxx.Main</mainClass>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
这样打包后jar文件中的MANIFEST.MF文件中的依赖描述就是用SNAPSHOT而不是用时间戳了。
我只用到了第一个问题。本文转自
http://ljhzzyx.blog.163.com/blog/static/38380312201110304566706/

maven一些问题的更多相关文章

  1. 【分享】标准springMVC+mybatis项目maven搭建最精简教程

    文章由来:公司有个实习同学需要做毕业设计,不会搭建环境,我就代劳了,顺便分享给刚入门的小伙伴,我是自学的JAVA,所以我懂的.... (大图直接观看显示很模糊,请在图片上点击右键然后在新窗口打开看) ...

  2. 理解Maven中的SNAPSHOT版本和正式版本

    Maven中建立的依赖管理方式基本已成为Java语言依赖管理的事实标准,Maven的替代者Gradle也基本沿用了Maven的依赖管理机制.在Maven依赖管理中,唯一标识一个依赖项是由该依赖项的三个 ...

  3. 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo

    Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...

  4. 安装eclipse的maven插件

    我们团队用maven来管理项目需要的库文件,其实以前都没听过maven,第一次接触这个,师兄要我直接去装下这个,开始以为还挺简单的,没想到中间遇到了一些小麻烦,现在把我成功安装maven的过程分享下, ...

  5. MAVEN学习-第一个Maven项目的构建

    MAVEN安装成功之后就可以进行项目的构建和管理了: 为什么要用maven进行项目的构建和管理? 对于初学者来说一个最直接的也是最容易里的优点在于JAR包的管理,相对于以前开发一个项目的时候我们需要用 ...

  6. Maven 代理设置

    在maven的安装目录下 %MAVEN_HOME%/conf/setting.xml 中进行设置 <proxies>    <!-- proxy     | Specificatio ...

  7. spring maven pom.xml设置

    spring pom.xml设置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...

  8. maven依赖查询地址

    http://search.maven.org/#search%7Cga%7C1%7C

  9. maven 中snapshot版本和release版本的区别

    maven中的仓库分为两种,snapshot快照仓库和release发布仓库.snapshot快照仓库用于保存开发过程中的不稳定版本,release正式仓库则是用来保存稳定的发行版本.定义一个组件/模 ...

  10. Maven多模块,Dubbo分布式服务框架,SpringMVC,前后端分离项目,基础搭建,搭建过程出现的问题

    现互联网公司后端架构常用到Spring+SpringMVC+MyBatis,通过Maven来构建.通过学习,我已经掌握了基本的搭建过程,写下基础文章为而后的深入学习奠定基础. 首先说一下这篇文章的主要 ...

随机推荐

  1. Android文字的阴影效果

    <!-- android:shadowDx 阴影的水平偏移量 即往右移的距离 --> <!-- android:shadowDy 阴影的垂直偏移量 即往下移的距离--> < ...

  2. Http协议简单解析及web请求过程

    HTTP协议: HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统. 基于HTTP协议的客户端/服务器请求响应机制的信息交换过程包含下面几个步骤: 1)    ...

  3. 多目标遗传算法 ------ NSGA-II (部分源码解析) 临时种群生成新父代种群 fillnds.c

    /* Nond-domination based selection routines */ # include <stdio.h> # include <stdlib.h> ...

  4. python学习之列表

    #coding:utf-81.#reverse方法将列表的元素反向存放,改变了原列表但不返回值x=[5,2,4,3,8]x.reverse() #x[::-1] 不改变list反向排序print x ...

  5. Java比较运算符

    注意哦: 1.  > . < . >= . <= 只支持左右两边操作数是数值类型 2.  == . != 两边的操作数既可以是数值类型,也可以是引用类型 public clas ...

  6. C# 导入文件日期格式(dd/MM/yyyy)

      最近项目导入数据日期变成了这样 这是因为转换成了美国时间 美国时间格式:MM/dd/yyyy 英国时间格式:dd/MM/yyyy     避免导入出现这个问题的话就需要将excel文档单元格样式设 ...

  7. 动态调用DLL函数有时正常,有时报Access violation的异常

    动态调用DLL函数有时正常,有时报Access violation的异常 typedef int (add *)(int a,int b); void test() {     hInst=LoadL ...

  8. Dreamweaver中清除php代码中多余空行的方法

    使用DW自带的搜索功能,利用正则表达式 使用正则表达式搜索:\r\n\s*\r\n即可搜到代码中的空行,再用回车符\n替换即可消除代码中的多余空行

  9. careercup-递归和动态规划 9.7

    9.7 编写函数,实现许多图片编辑软件都支持的“填充颜色”功能.给定一个屏幕(以二维数组表示,元素为颜色值).一个点和一个新的颜色值,将新颜色值填入这个点的周围区域,直到原来的颜色值全部改变. 类似l ...

  10. 关于js原型的面试题

    今天遇到关于javascript原型的一道面试题,现分析下: 原题如下: function A(){ } function B(a){ this.a = a; } function C(a){ if( ...