child module ….pom.xml does not existhtml
a.注意module的名稱是否正確,有時候命名問題會致使找不到項目的
b.注意一開始項目命名的規則問題注意一開始項目命名的規則問題java
使用maven-compiler-plugin 時
POM文件以下:web
<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 12spring
修改後以下,OK了 apache
<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.windows
<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.htmlapi
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包。這也避免了此類構件當部署到目標容器後產生包依賴衝突。 tomcat
依賴範圍控制哪些依賴在哪些classpath 中可用,哪些依賴包含在一個應用中。讓咱們詳細看一下每一種範圍:
compile (編譯範圍)
compile是默認的範圍;若是沒有提供一個範圍,那該依賴的範圍就是編譯範圍。編譯範圍依賴在全部的classpath 中可用,同時它們也會被打包。服務器
provided (已提供範圍)
provided 依賴只有在當JDK 或者一個容器已提供該依賴以後才使用。例如, 若是你開發了一個web 應用,你可能在編譯 classpath 中須要可用的Servlet API 來編譯一個servlet,可是你不會想要在打包好的WAR 中包含這個Servlet API;這個Servlet API JAR 由你的應用服務器或者servlet 容器提供。已提供範圍的依賴在編譯classpath (不是運行時)可用。它們不是傳遞性的,也不會被打包。mvc
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把剛纔刪除的信息還原。
一、
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/
二、
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>
三、
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時會彈出此對話框):
四、
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
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
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。
解決方案 一、在pom.xml文件中加入maven-resources-plugin配置
<dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4.3</version> </dependency>
二、在命令行下運行mvn install,
若是執行正確應該會在{user.home}\.m2\repository\org\apache\maven\plugins\maven-resources-plugin\下看到maven-resources-plugin-2.4.3.jar文件
三、刷新工程(右鍵工程選擇刷新項)
四、刷新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項目的操做步驟:
一、通常用 Eclipse 建項目的步驟以下:
(1)建一個普通項目
(2)建 pom.xml,定義好構件
(3)項目右鍵菜單,Configure -> Convert to Maven Project
(4)注意這些目錄和文件不要加入版本控制:.settings, target, .classpath, .project
二、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)