maven常见问题汇总
child module ….pom.xml does not exist
a.注意module的名称是否正确,有时候命名问题会导致找不到项目的
b.注意一开始项目命名的规则问题注意一开始项目命名的规则问题
使用maven-compiler-plugin 时
POM文件如下:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
[WARNING] Some problems were encountered while building the effective model for com.xxx.xxx:xxxx:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 72, column 12
修改后如下,OK了
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Configuring Your Compiler Plugin
Since the Compiler Plugin
executes automatically during their phases, you don't have to put
executions unlike many other plugins. However, you should specify the
version of the Compiler Plugin.
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>
http://maven.apache.org/plugins/maven-compiler-plugin/usage.html
maven install生成最终的构件包xxx-1.0.0.war(xxx-1.0.0.jar)后,
在其下的WEB-INF/lib(xxx-1.0.0.jar\BOOT-INF\lib)中,会包含我们被标注为scope=compile的构件的jar包,
而不会包含我们被标注为scope=provided的构件的jar包。这也避免了此类构件当部署到目标容器后产生包依赖冲突。
依赖范围控制哪些依赖在哪些classpath 中可用,哪些依赖包含在一个应用中。让我们详细看一下每一种范围:
compile (编译范围)
compile是默认的范围;如果没有提供一个范围,那该依赖的范围就是编译范围。编译范围依赖在所有的classpath 中可用,同时它们也会被打包。
provided (已提供范围)
provided 依赖只有在当JDK 或者一个容器已提供该依赖之后才使用。例如,
如果你开发了一个web 应用,你可能在编译 classpath 中需要可用的Servlet API
来编译一个servlet,但是你不会想要在打包好的WAR 中包含这个Servlet API;这个Servlet API JAR
由你的应用服务器或者servlet 容器提供。已提供范围的依赖在编译classpath (不是运行时)可用。它们不是传递性的,也不会被打包。
runtime (运行时范围)
runtime 依赖在运行和测试系统的时候需要,但在编译的时候不需要。比如,你可能在编译的时候只需要JDBC API JAR,而只有在运行的时候才需要JDBC
驱动实现。
test (测试范围)
test范围依赖 在一般的编译和运行时都不需要,它们只有在测试编译和测试运行阶段可用。
system (系统范围)
system范围依赖与provided 类似,但是你必须显式的提供一个对于本地系统中JAR
文件的路径。这么做是为了允许基于本地对象编译,而这些对象是系统类库的一部分。这样的构件应该是一直可用的,Maven
也不会在仓库中去寻找它。如果你将一个依赖范围设置成系统范围,你必须同时提供一个 systemPath
元素。注意该范围是不推荐使用的(你应该一直尽量去从公共或定制的 Maven 仓库中引用依赖)。
package阶段得到的是build目录下编译后的类包(jar),
install是把这个包和一些maven的元信息(比如pom.xml)复制到本地仓库,
assembly一般是把build结果和一些资源文件组成一个可以对外发布的包(zip包等),部署会用到。
Non-resolvable parent POM: Could not find artifact com.tangcheng:dubbo:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at no local POM @ line 14, column 13 -> [Help 2]
原因:
开始新的多个模块的项目时,其中的parent项目要先install一次。
就是新建了父项目后,一定要运行mvn install命令,才能建立子项目
解决办法:把pom中的modules删除,然后执行mvn install。然后ctrl+z把刚才删除的信息还原。
1、
Failure to transfer org.apache.poi:poi-ooxml-schemas:jar:3.10.1 from
http://repo.maven.apache.org/maven2 was cached in the local repository,
resolution will not be reattempted until the update interval of central has elapsed or updates are forced.
Original
error: Could not transfer artifact
org.apache.poi:poi-ooxml-schemas:jar:3.10.1 from/to central
(http://repo.maven.apache.org/maven2):
Connection reset。
这句话的意思是: 对于这个包从maven中心传输到本地仓库失败,决定不会重新尝试下载jar包,直到mavne再改更新索引,或强制更新。
实际的解决办法是:直接去本地仓库(local repository),把这个org.apache.poi存放的目录删除掉(因为包没有下载下来),
(1)刷新你的项目(在项目上点右键-->刷新);
(2)在你的项目上右击,选择maven--->update(刷新Maven配置)就可以了,让maven重新下载;
(3)编译maven项目。在项目上点右键-->Run As -->Maven build
使用说明:
如果pom.xml中配置的jar不能下载,提示pom.xml中报错,反复使用(1)和(2)操作;
如果pom.xml文件没有报错,就使用(3)来处理;
http://zhanghua.1199.blog.163.com/blog/static/464498072013529936189/
2、
Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
注:
如果项目编码设为utf-8,maven-resources-plugin如果使用windows自带的GBK编码,则就会出现乱码。乱码后就会编译不过。
解决办法:
在pom.xml中build-plugins下将plugin:maven-resources-plugin设置为与项目的编码一致即可。譬如此处设置为UTF-8
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<finalName>defalut_goal</finalName>
<defaultGoal>compile</defaultGoal>
</build>
3、
eclipse安装的maven插件是m2eclipse,使用命令行时就已经指定了phase,而使用m2eclipse的【Run As】-【Maven build】时并未为其指定goal或phase
在pom.xml中指定defaultGoal的方式:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<finalName>defalut_goal</finalName>
<defaultGoal>compile</defaultGoal>
</build>
此处指定为compile
在eclipse中指定(第一次使用使用Maven build时会弹出此对话框):
4、
maven 下载 源码和javadoc命令
(1)Maven命令下载源码和javadocs
当在IDE中使用Maven时如果想要看引用的jar包中类的源码和javadoc需要通过maven命令下载这些源码,然后再进行引入,通过mvn命令能够容易的达到这个目的:
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
命令使用方法:首先进入到相应的pom.xml目录中,然后执行以上命令:
第一个命令是尝试下载在pom.xml中依赖的文件的源代码。
第二个命令:是尝试下载对应的javadocs
但是有可能一些文件没有源代码或者javadocs
(2)通过配置文件添加
打开maven配置文件 setting.xml文件(.../.m2/settings.xml) 增加如下配置:
<profiles>
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
(3)配置eclipse
Window > Preferences > Maven and checking the "Download Artifact Sources" and "Download Artifact JavaDoc" options
http://blog.csdn.net/topwqp/article/details/8902863
Setting the -source and -target of the Java Compiler
Sometimes when you may need to compile a certain project to a different version than what you are currently using. The javac can accept such command using -source and -target. The Compiler Plugin can also be configured to provide these options during compilation.
For example, if you want to enable assertions (-source 1.4) and also want the compiled classes to be compatible with JVM 1.4 (-target 1.4), you can then put:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
http://jynine.iteye.com/blog/1890842
Maven Compiler Plugin
The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.
Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.
Other compilers than javac can be used and work has already started on AspectJ, .NET, and C#.
This Compiler Plugin corresponds to Maven 1.x's Java Plugin.
http://maven.apache.org/plugins/maven-compiler-plugin/
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project rruHotloadFileMaker: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[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
-
在eclipse的菜单中,进入 Window > Preferences > Java > Installed JREs > Execution Environments,选择JavaSE-1.6, 在右侧选择jdk.
-
然后在maven菜单中使用 “update project ...(刷新maven配置)
http://blog.csdn.net/fox_lht/article/details/16369147
使用JDK1.8安装后,会在Win10 path中新增 C:\ProgramData\Oracle\Java\javapath
这样也会导致出现“No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?”
解决的办法是把“C:\ProgramData\Oracle\Java\javapath”从path中删除,再把java.exe所在路径添加到path中
在别的机子上创建一个maven工程,复制到本机上导入,出现pom.xml文件错误,提示错误如下
Multiple annotations found at this line:
- Execution default-testResources of goal org.apache.maven.plugins:maven-resources- plugin:2.4.3:testResources failed:
Plugin
org.apache.maven.plugins:maven-resources-plugin:2.4.3 or one of its
dependencies could not be resolved: Failed to collect
dependencies for org.apache.maven.plugins:maven-resources-plugin:jar:2.4.3 ()
错误信息出现在pom头的project标签,project标签内容是 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
原因 这是由于缺少maven-resources-plugin-2.4.3.jar文件。这个文件是在{user.home}\.m2\repository\org\apache\maven\plugins\maven-resources-plugin\下。{user.home}是maven的配置路径,一般是我的文档,是window-preferences-MyEclipse-Maven4MyEclipse-User Setting里面的Local Repository。
解决方案 1、在pom.xml文件中加入maven-resources-plugin配置
<dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4.3</version> </dependency>
2、在命令行下运行mvn install,
如果执行正确应该会在{user.home}\.m2\repository\org\apache\maven\plugins\maven-resources-plugin\下看到maven-resources-plugin-2.4.3.jar文件
3、刷新工程(右键工程选择刷新项)
4、刷新maven配置,右键工程节点,选择Maven-Update Project Configuration
http://blog.csdn.net/imlmy/article/details/8268293
用eclipse装m2eclipse的时候装完后创建项目的时候报错:
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE from any of the configured repositories.
解决方式:
1.从http://maven.oschina.net/content/groups/public/org/apache/maven/archetypes/maven-archetype-quickstart/
下载最新版maven-archetype-quickstart-1.1.jar
2.命令行到下载目录下执行mvn
install:install-file -DgroupId=org.apache.maven.archetypes
-DartifactId=maven-archetype-quickstart -Dversion=1.1 -Dpackaging=jar
-Dfile=maven-archetype-quickstart-1.1.jar
http://www.cnblogs.com/xsi640/p/3758095.html
在install maven-archetype-j2ee-simple-1.0-alpha-4.jar后,使用命令行或m2eclipse插件均不能创建 archetype为maven-archetype-j2ee-simple的项目
m2eclipse插件报错:
Unable to create project from archetype [org.apache.maven.archetypes:maven-archetype-j2ee-simple:RELEASE]
Error merging velocity templates
使用mvn archetype:generate后的报错信息:
[WARNING] Error reading archetype catalog http://repo.maven.apache.org/maven2
org.apache.maven.archetype.source.ArchetypeDataSourceException: Error parsing a
chetype catalog.
at org.apache.maven.archetype.source.CatalogArchetypeDataSource.readCat
log(CatalogArchetypeDataSource.java:194)
at org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource.d
wnloadCatalog(RemoteCatalogArchetypeDataSource.java:121)
at org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource.g
tArchetypeCatalog(RemoteCatalogArchetypeDataSource.java:87)
at org.apache.maven.archetype.DefaultArchetypeManager.getRemoteCatalog(
efaultArchetypeManager.java:216)
at org.apache.maven.archetype.DefaultArchetypeManager.getRemoteCatalog(
efaultArchetypeManager.java:205)
at org.apache.maven.archetype.ui.generation.DefaultArchetypeSelector.ge
ArchetypesByCatalog(DefaultArchetypeSelector.java:200)
at org.apache.maven.archetype.ui.generation.DefaultArchetypeSelector.se
ectArchetype(DefaultArchetypeSelector.java:71)
at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.exec
te(CreateProjectFromArchetypeMojo.java:181)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Defaul
BuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecuto
.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecuto
.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecuto
.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProj
ct(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProj
ct(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThr
adedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecyc
eStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Lau
cher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.ja
a:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(L
uncher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java
356)
Caused by: org.codehaus.plexus.util.xml.pull.XmlPullParserException: Expected r
ot element 'archetype-catalog' but found 'html' (position: START_TAG seen <html
... @1:6)
at org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Reade
.read(ArchetypeCatalogXpp3Reader.java:737)
at org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Reade
.read(ArchetypeCatalogXpp3Reader.java:554)
at org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Reade
.read(ArchetypeCatalogXpp3Reader.java:568)
at org.apache.maven.archetype.source.CatalogArchetypeDataSource.readCat
log(CatalogArchetypeDataSource.java:186)
... 28 more
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/m
ven-archetype-j2ee-simple/1.0/maven-archetype-j2ee-simple-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:59 min
maven打包编译时后台一直输出警告信息
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
找了半天,原来只要在pom.xml文件中增加一个配置项即可
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
http://blog.csdn.net/crazycoder2010/article/details/7077233
编译(执行命令:mvn install)的时候,又报错
Failed to execute goal on project ui:
Could not resolve dependencies for project <<package>>:ui:war:1.0: Failed to collect dependencies for [javax.servlet:servlet-api:jar:2.5 (provided),
org.springframework:spring-core:jar:3.0.5.RELEASE (compile),
org.springframework:spring-web:jar:3.0.5.RELEASE (compile),
cglib:cglib:jar:2.2 (compile), org.springframework:spring-aop:jar:3.0.5.RELEASE (compile),
org.springframework:spring-webmvc:jar:3.0.5.RELEASE (compile), org.springframework:spring-context:jar:3.0.5.RELEASE (compile),
org.freemarker:freemarker:jar:2.3.18 (compile), gr.imu.ntua.tweetinspire:services:jar:1.0 (compile),
org.cloudfoundry.samples:tomcat7-standalone:tar.gz:7.0.29 (compile), org.slf4j:slf4j-api:jar:1.6.1 (compile),
org.slf4j:slf4j-log4j12:jar:1.6.1 (compile), org.slf4j:jcl-over-slf4j:jar:1.6.1 (compile),
commons-logging:commons-logging:jar:1.1.1 (compile), junit:junit:jar:4.8.1 (test),
org.springframework:spring-test:jar:3.0.5.RELEASE (test), org.dbunit:dbunit:jar:2.4.8 (test)]: Failed to read artifact descriptor for org.cloudfoundry.samples:tomcat7-standalone:tar.gz:7.0.29: Could not transfer artifact org.cloudfoundry.samples:tomcat7-standalone:pom:7.0.29 from/to jets3t (http://www.jets3t.org/maven2): Access denied to: http://www.jets3t.org/maven2/org/cloudfoundry/samples/tomcat7-standalone/7.0.29/tomcat7-standalone-7.0.29.pom, ReasonPhrase:Forbidden
解决方法一:
后面就将pom.xml中的一段依赖jdk的代码注释掉,
<dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> <version>1.5.0</version> <scope>system</scope> <systemPath>D:\java\jdk\lib\tools.jar </systemPath> </dependency>
然后清理Eclipse项目(点击Eclipse编辑器中的Project, 然后点击clean),再将上面这段代码的注释取消掉。
解决方法二: 如果以上方法还没有解决问题,还可以尝试关闭maven项目在项目启动时自动下载更新仓库选项。操作方法如下:
点击Eclipse中的window菜单,选择Preferences,点击左侧的Maven ,然后去掉Download repository index updates on startup选项前面的对勾,然后清理Eclipse项目(Project-->clean)。
http://blog.csdn.net/daydayupzzc/article/details/38818045
使用maven创建web工程,将Spring配置文件applicationContext.xml放在src/resource下,用eclipse编译时提示class
path resource [applicationContext.xml] cannot be opened because it does
not exist错误。但是用mvn clean package命令编译时成功的。
web.xml配置的如下
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param>
用google搜索一下(之前google用不了,用百度搜到蛋疼),发现是由于classpath不是指向resource路径,导致一直找不到文件。需要在classpath后面加个*,这样就解决问题了。
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext.xml</param-value> </context-param>
http://blog.csdn.net/imlmy/article/details/8263531
创建Maven项目的操作步骤:
1、一般用 Eclipse 建项目的步骤如下:
(1)建一个普通项目
(2)建 pom.xml,定义好构件
(3)项目右键菜单,Configure -> Convert to Maven Project
(4)注意这些目录和文件不要加入版本控制:.settings, target, .classpath, .project
2、http://www.cnblogs.com/candle806/p/3439469.html
java.lang.NoClassDefFoundError: org/junit/runners/model/MultipleFailureException
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.withAfterClasses(SpringJUnit4ClassRunner.java:188)
at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:145)
at org.junit.runners.ParentRunner.run(ParentRunner.java:235)