1. 程式人生 > >Maven安裝成功後,總是無法成功mvn install?解決方法是JDK設定的問題。

Maven安裝成功後,總是無法成功mvn install?解決方法是JDK設定的問題。

[INFO] Changes detected - recompiling the module!
[INFO] Compiling 164 source files to G:\Maven\jfinal\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:24 min
[INFO] Finished at: 2017-04-24T19:26:25+08:00
[INFO] Final Memory: 13M/122M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project jfinal_cms: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR]
[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

G:\Maven\jfinal>

我重新執行mvn install,直接報錯

G:\Maven\jfinal>mvn install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.jflyfox:jfinal_cms:war:4.5.0
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 162, column 12
[WARNING] The expression ${artifactId} is deprecated. Please use ${project.artifactId} instead.
[WARNING] The expression ${artifactId} is deprecated. Please use ${project.artifactId} instead.
[WARNING] The expression ${artifactId} is deprecated. Please use ${project.artifactId} instead.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jfinal_cms 4.5.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.ibeetl:beetl:jar:2.7.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jfinal_cms ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 8 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ jfinal_cms ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 164 source files to G:\Maven\jfinal\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.179 s
[INFO] Finished at: 2017-04-24T19:31:02+08:00
[INFO] Final Memory: 10M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project jfinal_cms: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR]
[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和myeclipse中重新配置JDK路徑還是無法解決。

不知道是不是和我最開始嫌棄maven下載太慢,在maven目錄中修改了setting.xml下載路徑,換成aliyun埠。雖然貌似前幾次下載依舊不成功,我反覆嘗試mvn install,結果就杯具了。。。。

-----------------------------------------------------分割線---------------------------------------------------------------

出現這個而問題之後我改變了一個思路來做,我重新設定了maven的本地倉庫地址,把預設到C:\Users\hasee\.m2\repository的地址改成了我自己設定的地址:D:\Mavenm2\m2\repository;具體的修改方法看這兩個引用連結:

http://www.cnblogs.com/liunanjava/archive/2015/11/05/4936037.html 或者http://xiaocao000.iteye.com/blog/1758639 這兩篇博主的文章都可以,也許覺得不夠詳細,那麼可以再參考百度問答的一個連結:https://zhidao.baidu.com/question/1769645808405821420.html

言歸正傳,這次我修改了本地倉庫地址後,重新到專案檔案下用控制檯輸入mvn install這次就沒有報之前的錯誤,報出了一個新錯誤:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:53 h
[INFO] Finished at: 2017-04-24T21:48:55+08:00
[INFO] Final Memory: 11M/127M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project jfinal_cms: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile failed: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.apache.maven:maven-artifact:jar:2.0.9, org.apache.maven.shared:maven-shared-utils:jar:0.1, com.google.collections:google-collections:jar:1.0: Could not transfer artifact org.apache.maven:maven-artifact:jar:2.0.9 from/to central (https://repo.maven.apache.org/maven2): GET request of: org/apache/maven/maven-artifact/2.0.9/maven-artifact-2.0.9.jar from central failed: Read timed out -> [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/PluginResolutionException

沒有想到竟然還是會報錯。。。。。。。。。

修改maven目錄conj下的setting.xml檔案和本地倉庫下的setting.xml檔案中的:

<profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.8</id>

      <activation>
        <jdk>1.8</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk18</id>
          <name>Repository for JDK 1.8 builds</name>
          <url>http://www.myhost.com/maven/jdk18</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>

把其中的JDK版本全部修改成自己本機的JDK版本,不知道的可以控制檯Java -version檢視

修改完成之後我就把我的本機本地倉庫中的maven下載清空,控制檯到專案根目錄直接mvn install,現在重新下載中:


希望這次可以成功啊

----------------------------------

這次果然成功了!!!

[INFO] Installing G:\Maven\jfinal\target\jfinal_cms.war to D:\Mavenm2\m2\repository\com\jflyfox\jfinal_cms\4.5.0\jfinal_cms-4.5.0.war
[INFO] Installing G:\Maven\jfinal\pom.xml to D:\Mavenm2\m2\repository\com\jflyfox\jfinal_cms\4.5.0\jfinal_cms-4.5.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10:12 min
[INFO] Finished at: 2017-04-25T14:27:06+08:00
[INFO] Final Memory: 22M/156M
[INFO] ------------------------------------------------------------------------

這次竟然成功了,困擾我兩天的問題。

仔細思考了一下,這個問題的原因還是JDK的配置的問題,按照網上查出來的相關解決辦法,我一步一步的來改變了Eclipse和Myeclipse中的maven設定和JDK路徑;

依然出現專案目錄下mvn -install不成功的情況;都是提示JDK版本不一致或者是沒有JDK的執行環境;

我最後檢視maven的配置檔案setting.xml修改其中間的JDK配置, 按照本機的配置來,就沒有報錯了。

所以最後的解決辦法是 再三確認JDK環境為何不能被Maven識別?????

1,要麼就是eclipse和myeclipse中路徑有問題;

2,要麼就是POM.xml檔案中JDK不匹配;

3,要麼就是Maven目錄和本地.m2本地倉庫目錄中的setting.xml中的JDK與本機JDK環境不匹配;

當然這三個前提是建立在確認JDK環境正確安裝,環境變數都已經正確配置,Maven正確安裝等這些情況下。