maven常見問題匯總 專題


 


child module ….pom.xml does not exist

a.注意module的名稱是否正確,有時候命名問題會導致找不到項目的
b.注意一開始項目命名的規則問題注意一開始項目命名的規則問題

 

報錯信息:

[INFO] 
[INFO] --- maven-assembly-plugin:2.6:single (app) @ api ---
[INFO] Reading assembly descriptor: src/assembly/assembly.xml
[ERROR] OS=Windows and the assembly descriptor contains a *nix-specific root-relative-reference (starting with slash) /bin
[ERROR] OS=Windows and the assembly descriptor contains a *nix-specific root-relative-reference (starting with slash) /lib
[INFO] Building tar: F:\project\workspace\com\api\target\com-app.tar.gz
[ERROR] OS=Windows and the assembly descriptor contains a *nix-specific root-relative-reference (starting with slash) /bin
[ERROR] OS=Windows and the assembly descriptor contains a *nix-specific root-relative-reference (starting with slash) /lib
[INFO] Building zip: F:\project\workspace\com\api\target\com-app.zip

解決辦法:
The working solution is to specify the empty outputDirectory:

<fileSets>
    <fileSet>
        <directory>${basedir}/src/main/resources</directory>
        <outputDirectory></outputDirectory>
    </fileSet>
</fileSets>

有錯誤產生的assembly.xml

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
    <id>app</id>
    <formats>
        <format>tar.gz</format>
        <format>zip</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/bin</directory>
            <outputDirectory>/bin</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <includes>
                <include>*.jar</include>
            </includes>
            <excludes>
                <exclude>*sources.jar</exclude>
            </excludes>
            <outputDirectory>/lib</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

 https://stackoverflow.com/questions/28500401/maven-assembly-plugin-warning-the-assembly-descriptor-contains-a-filesystem-roo

 

 

 

使用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



  1. 在eclipse的菜單中,進入 Window > Preferences > Java > Installed JREs > Execution Environments,選擇JavaSE-1.6, 在右側選擇jdk.

  2. 然后在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)

使用maven-source-plugin打包包含源碼
maven-source-plugin插件打出的包包含源碼,引用包含源碼的包,在eclipse等ide中查看源文件時可以更易讀些。
要生成帶source的jar, 需要在pom.xml中包含下面的插件

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

然后執行mvn install, 打包成功的話,就可以在target文件夾中找到帶source的jar包,通常命名為 xxx-version-sources.jar

 

maven打包編譯的錯誤:sun.misc.BASE64Decoder是Sun的專用API,可能會在未來版本中刪除

今天遇到 sun.misc.BASE64Decoder是Sun的專用API,可能會在未來版本中刪除 的錯誤

算是maven的一個bug吧。

maven-compiler-plugin 2.3.2 發布以后把這個錯誤改成了告警。

所以只要將這個插件升級一下就好了。


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>

不料有出現了
程序包com.sun.image.codec.jpeg不存在
的問題,繼續查,這次需要給環境變量加一個jar包。
最終完美的解決辦法:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<verbose />
<bootclasspath>${java.home}/lib/rt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>

--------------------- 
作者:天天 
來源:CSDN 
原文:https://blog.csdn.net/tiantiandjava/article/details/41483311 
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

 

resolution will not be reattempted until the update interval of XXX has elapsed or updates are force

環境

Java:1.8
maven:3.6.1

前言

我只是在pom.xml文件中,將version的數字改了下,結果出問題了。
包總是下不下來。所以idea的引用也沒有更新。

其實這是一個很簡單的錯誤,奈何我以前的工作都是手動導包。導致我maven的能力偏弱。

錯誤消息

[ERROR] Failed to execute goal on project model: 
Could not resolve dependencies for project com.xingren.clinic:model:jar:1.0.0-SNAPSHOT: Failure to find com.xingren.service:medevac-client:jar:1.2.33-SNAPSHOT in http://nexus.aihaisi.com/repository/public/ was cached in the local repository, 
resolution will not be reattempted until the update interval of xr-public has elapsed or updates are forced -> [Help 1]

主要錯誤消息,如題:
就是resolution will not be reattempted until the update interval of XXX has elapsed or updates are force

意思就是:

在 XXX的更新間隔過去或強制更新之前,不會重新嘗試解析。

如果你去本地的maven倉庫,你會發現,其只有lastUpdate結尾的文件,沒有jar包。

這個時候,你無論怎么點擊IDEA中的Reimports All Maven Projects都是沒有用的。原因上面也說了,要么等更新時間過去,要么強制更新。
maven的默認更新時間為day,即一天更新一次。

所以我們一般都是采用強制更新的方式。

解決辦法

命令行的方式

mvn clean install -U 

修改settings.xml

添加<updatePolicy>always</updatePolicy>

<repositories>
   <repository>
     <id>xr-snapshots</id>
       <url>http://nexus.alibaba.com/repository/snapshots/</url>
     <snapshots>
       <enabled>true</enabled>
       <!-- 注意 -->
       <updatePolicy>always</updatePolicy>
     </snapshots>
     <releases>
       <enabled>false</enabled>
       <!-- 注意 -->
       <updatePolicy>always</updatePolicy>
     </releases>
   </repository>
 </repositories>

<pluginRepositories>
   <pluginRepository>
     <id>xr-plugins</id>
     <name>xingren plugins</name>
     <url>http://nexus.alibaba.com/repository/public/</url>
     <releases>
         <enabled>true</enabled>
         <!-- 注意 -->
         <updatePolicy>always</updatePolicy>
     </releases>
      <snapshots>
          <enabled>true</enabled>
          <!-- 注意 -->
          <updatePolicy>always</updatePolicy>
      </snapshots>
   </pluginRepository>
</pluginRepositories>

 

我采用的是使用命令行。

總結

在確定遠程倉庫jar包存在,配置也沒有錯的情況下,
使用強制更新。

參考地址:
https://www.cnblogs.com/huojiao2006/articles/5195965.html
https://stackoverflow.com/questions/4701532/force-maven-update

https://blog.csdn.net/u013066244/article/details/91986308

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM