maven常见问题汇总
child module ….pom.xml does not exist
a.注意module的名稱是否正確,有時候命名問題會導致找不到項目的
b.注意一開始項目命名的規(guī)則問題注意一開始項目命名的規(guī)則問題
使用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生成最終的構(gòu)件包xxx-1.0.0.war(xxx-1.0.0.jar)后,
在其下的WEB-INF/lib(xxx-1.0.0.jarBOOT-INFlib)中,會包含我們被標注為scope=compile的構(gòu)件的jar包,
而不會包含我們被標注為scope=provided的構(gòu)件的jar包。這也避免了此類構(gòu)件當部署到目標容器后產(chǎn)生包依賴沖突。
依賴范圍控制哪些依賴在哪些classpath 中可用,哪些依賴包含在一個應用中。讓我們詳細看一下每一種范圍:
compile (編譯范圍)
compile是默認的范圍;如果沒有提供一個范圍,那該依賴的范圍就是編譯范圍。編譯范圍依賴在所有的classpath 中可用,同時它們也會被打包。
provided (已提供范圍)
provided 依賴只有在當JDK 或者一個容器已提供該依賴之后才使用。例如,
如果你開發(fā)了一個web 應用,你可能在編譯 classpath 中需要可用的Servlet API
來編譯一個servlet,但是你不會想要在打包好的WAR 中包含這個Servlet API;這個Servlet API JAR
由你的應用服務器或者servlet 容器提供。已提供范圍的依賴在編譯classpath (不是運行時)可用。它們不是傳遞性的,也不會被打包。
runtime (運行時范圍)
runtime 依賴在運行和測試系統(tǒng)的時候需要,但在編譯的時候不需要。比如,你可能在編譯的時候只需要JDBC API JAR,而只有在運行的時候才需要JDBC
驅(qū)動實現(xiàn)。
test (測試范圍)
test范圍依賴 在一般的編譯和運行時都不需要,它們只有在測試編譯和測試運行階段可用。
system (系統(tǒng)范圍)
system范圍依賴與provided 類似,但是你必須顯式的提供一個對于本地系統(tǒng)中JAR
文件的路徑。這么做是為了允許基于本地對象編譯,而這些對象是系統(tǒng)類庫的一部分。這樣的構(gòu)件應該是一直可用的,Maven
也不會在倉庫中去尋找它。如果你將一個依賴范圍設(shè)置成系統(tǒng)范圍,你必須同時提供一個 systemPath
元素。注意該范圍是不推薦使用的(你應該一直盡量去從公共或定制的 Maven 倉庫中引用依賴)。
package階段得到的是build目錄下編譯后的類包(jar),
install是把這個包和一些maven的元信息(比如pom.xml)復制到本地倉庫,
assembly一般是把build結(jié)果和一些資源文件組成一個可以對外發(fā)布的包(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刪除,然后執(zhí)行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中心傳輸?shù)奖镜貍}庫失敗,決定不會重新嘗試下載jar包,直到mavne再改更新索引,或強制更新。
實際的解決辦法是:直接去本地倉庫(local repository),把這個org.apache.poi存放的目錄刪除掉(因為包沒有下載下來),
(1)刷新你的項目(在項目上點右鍵-->刷新);
(2)在你的項目上右擊,選擇maven--->update(刷新Maven配置)就可以了,讓maven重新下載;
(3)編譯maven項目。在項目上點右鍵-->RunAs-->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!
注:
如果項目編碼設(shè)為utf-8,maven-resources-plugin如果使用windows自帶的GBK編碼,則就會出現(xiàn)亂碼。亂碼后就會編譯不過。
解決辦法:
在pom.xml中build-plugins下將plugin:maven-resources-plugin設(shè)置為與項目的編碼一致即可。譬如此處設(shè)置為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,使用命令行時就已經(jīng)指定了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目錄中,然后執(zhí)行以上命令:
第一個命令是嘗試下載在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-sourceand-targetof the Java Compiler
Sometimes when you may need to compile a certain project to a different version than what you are currently using. Thejavaccan accept such command using-sourceand-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 usingjavac, you must configure the plugin optionforceJavacCompilerUse.
Also note that at present the defaultsourcesetting is1.5and the defaulttargetsetting is1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should setsourceandtargetas described inSetting the -source and -target of the Java Compiler.
Other compilers thanjavaccan 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, 在右側(cè)選擇jdk.
然后在maven菜單中使用 “update project ...(刷新maven配置)
http://blog.csdn.net/fox_lht/article/details/16369147
使用JDK1.8安裝后,會在Win10 path中新增C:ProgramDataOracleJavajavapath
這樣也會導致出現(xiàn)“No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?”
解決的辦法是把“C:ProgramDataOracleJavajavapath”從path中刪除,再把java.exe所在路徑添加到path中
在別的機子上創(chuàng)建一個maven工程,復制到本機上導入,出現(xiàn)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 ()
錯誤信息出現(xiàn)在pom頭的project標簽,project標簽內(nèi)容是 <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}.m2epositoryorgapachemavenpluginsmaven-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,
如果執(zhí)行正確應該會在{user.home}.m2epositoryorgapachemavenpluginsmaven-resources-plugin下看到maven-resources-plugin-2.4.3.jar文件
3、刷新工程(右鍵工程選擇刷新項)
4、刷新maven配置,右鍵工程節(jié)點,選擇Maven-Update Project Configuration
http://blog.csdn.net/imlmy/article/details/8268293
用eclipse裝m2eclipse的時候裝完后創(chuàng)建項目的時候報錯:
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.命令行到下載目錄下執(zhí)行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插件均不能創(chuàng)建 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
編譯(執(zhí)行命令: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:javajdklib ools.jar </systemPath> </dependency>
然后清理Eclipse項目(點擊Eclipse編輯器中的Project, 然后點擊clean),再將上面這段代碼的注釋取消掉。
解決方法二: 如果以上方法還沒有解決問題,還可以嘗試關(guān)閉maven項目在項目啟動時自動下載更新倉庫選項。操作方法如下:
點擊Eclipse中的window菜單,選擇Preferences,點擊左側(cè)的Maven ,然后去掉Download repository index updates on startup選項前面的對勾,然后清理Eclipse項目(Project-->clean)。
http://blog.csdn.net/daydayupzzc/article/details/38818045
使用maven創(chuàng)建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用不了,用百度搜到蛋疼),發(fā)現(xiàn)是由于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
創(chuàng)建Maven項目的操作步驟:
1、一般用 Eclipse 建項目的步驟如下:
(1)建一個普通項目
(2)建 pom.xml,定義好構(gòu)件
(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)
總結(jié)
以上是生活随笔為你收集整理的maven常见问题汇总的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【原创】DMA
- 下一篇: PymuPDF实现PDF文字和图片的修改