idea 使用maven報錯已解決


maven核心思想:約束大於配置。

maven下載與安裝,各位大俠寫的都很好,所以直接上車:

下載安裝:https://blog.csdn.net/c_staunch/article/details/100981699

maven教程:https://www.runoob.com/maven/maven-tutorial.html  或者看看  https://blog.csdn.net/lovequanquqn/article/details/81627807

在idea中使用maven:


1、新建項目時,選則maven。

 

 

2、 在下圖選擇使用自己安裝的版本或者idea自帶的版本

 

 

 PS:idea在新建項目時,會將上面三個域重置為默認值。因為這時配置的是該項目中的選項,不是全局選項。

全局配置:file ---new projects settings---settingt for new projects,找到maven 進行設置;(PPS:不同idea版本,設置位置不同,貌似有的在other settings中)

3、正常創建后,就可以自動下載所需內容了。

4、創建完成后,項目目錄(選擇了webapp模板)


然而

在idea中創建maven項目時,插件全部不能下載:

 

 報錯信息如下:

 

 Lifecycle-- clean-- run maven bilud時 報錯信息如下:

D:\myeclipse18\jdk1.8.0_181\bin\java.exe -Dmaven.multiModuleProjectDirectory=D:\IDEA\maven01 -Dmaven.home=D:\Maven\apache-maven-3.6.3 
-Dclassworlds.conf=D:\Maven\apache-maven-3.6.3\bin\m2.conf "-Dmaven.ext.class.path=D:\IDEA\IntelliJ IDEA 2020.3.2\plugins\maven\lib\maven-event-listener.jar"
"-javaagent:D:\IDEA\IntelliJ IDEA 2020.3.2\lib\idea_rt.jar=51697:D:\IDEA\IntelliJ IDEA 2020.3.2\bin"
-Dfile.encoding=UTF-8 -classpath D:\Maven\apache-maven-3.6.3\boot\plexus-classworlds-2.6.0.jar;
D:\Maven\apache-maven-3.6.3\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2020.3.2
-s D:\Maven\apache-maven-3.6.3\conf\settings.xml clean [INFO] Scanning for projects... [INFO] [INFO] ------------------------< org.example:maven01 >------------------------- [INFO] Building maven01 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- Downloading from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.964 s [INFO] Finished at: 2021-03-03T12:05:28+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for
org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5
from/to alimaven (http://maven.aliyun.com/nexus/content/repositories/central/):
Transfer failed for
http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target -> [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 Process finished with exit code 1

 找了很多方法,檢查很多遍settings文件,都不成。回頭看報錯

提取關鍵報錯信息:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target -> [Help 1]-----關鍵

看起來是缺少某個證書,於是:https://www.cnblogs.com/xiaoping1993/p/9717649.html   或者 https://blog.csdn.net/faye0412/article/details/6883879

代碼如下:

import java.io.*;
import java.net.URL;
 
import java.security.*;
import java.security.cert.*;
 
import javax.net.ssl.*;
 
public class InstallCert {
 
    public static void main(String[] args) throws Exception {
    String host;
    int port;
    char[] passphrase;
    if ((args.length == 1) || (args.length == 2)) {
        String[] c = args[0].split(":");
        host = c[0];
        port = (c.length == 1) ? 443 : Integer.parseInt(c[1]);
        String p = (args.length == 1) ? "changeit" : args[1];
        passphrase = p.toCharArray();
    } else {
        System.out.println("Usage: java InstallCert <host>[:port] [passphrase]");
        return;
    }
 
    File file = new File("jssecacerts");
    if (file.isFile() == false) {
        char SEP = File.separatorChar;
        File dir = new File(System.getProperty("java.home") + SEP
            + "lib" + SEP + "security");
        file = new File(dir, "jssecacerts");
        if (file.isFile() == false) {
        file = new File(dir, "cacerts");
        }
    }
    System.out.println("Loading KeyStore " + file + "...");
    InputStream in = new FileInputStream(file);
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    ks.load(in, passphrase);
    in.close();
 
    SSLContext context = SSLContext.getInstance("TLS");
    TrustManagerFactory tmf =
        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(ks);
    X509TrustManager defaultTrustManager = (X509TrustManager)tmf.getTrustManagers()[0];
    SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);
    context.init(null, new TrustManager[] {tm}, null);
    SSLSocketFactory factory = context.getSocketFactory();
 
    System.out.println("Opening connection to " + host + ":" + port + "...");
    SSLSocket socket = (SSLSocket)factory.createSocket(host, port);
    socket.setSoTimeout(10000);
    try {
        System.out.println("Starting SSL handshake...");
        socket.startHandshake();
        socket.close();
        System.out.println();
        System.out.println("No errors, certificate is already trusted");
    } catch (SSLException e) {
        System.out.println();
        e.printStackTrace(System.out);
    }
 
    X509Certificate[] chain = tm.chain;
    if (chain == null) {
        System.out.println("Could not obtain server certificate chain");
        return;
    }
 
    BufferedReader reader =
        new BufferedReader(new InputStreamReader(System.in));
 
    System.out.println();
    System.out.println("Server sent " + chain.length + " certificate(s):");
    System.out.println();
    MessageDigest sha1 = MessageDigest.getInstance("SHA1");
    MessageDigest md5 = MessageDigest.getInstance("MD5");
    for (int i = 0; i < chain.length; i++) {
        X509Certificate cert = chain[i];
        System.out.println
            (" " + (i + 1) + " Subject " + cert.getSubjectDN());
        System.out.println("   Issuer  " + cert.getIssuerDN());
        sha1.update(cert.getEncoded());
        System.out.println("   sha1    " + toHexString(sha1.digest()));
        md5.update(cert.getEncoded());
        System.out.println("   md5     " + toHexString(md5.digest()));
        System.out.println();
    }
 
    System.out.println("Enter certificate to add to trusted keystore or 'q' to quit: [1]");
    String line = reader.readLine().trim();
    int k;
    try {
        k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1;
    } catch (NumberFormatException e) {
        System.out.println("KeyStore not changed");
        return;
    }
 
    X509Certificate cert = chain[k];
    String alias = host + "-" + (k + 1);
    ks.setCertificateEntry(alias, cert);
 
    OutputStream out = new FileOutputStream("jssecacerts");
    ks.store(out, passphrase);
    out.close();
 
    System.out.println();
    System.out.println(cert);
    System.out.println();
    System.out.println
        ("Added certificate to keystore 'jssecacerts' using alias '"
        + alias + "'");
    }
 
    private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();
 
    private static String toHexString(byte[] bytes) {
    StringBuilder sb = new StringBuilder(bytes.length * 3);
    for (int b : bytes) {
        b &= 0xff;
        sb.append(HEXDIGITS[b >> 4]);
        sb.append(HEXDIGITS[b & 15]);
        sb.append(' ');
    }
    return sb.toString();
    }
 
    private static class SavingTrustManager implements X509TrustManager {
 
    private final X509TrustManager tm;
    private X509Certificate[] chain;
 
    SavingTrustManager(X509TrustManager tm) {
        this.tm = tm;
    }
 
    public X509Certificate[] getAcceptedIssuers() {
        throw new UnsupportedOperationException();
    }
 
    public void checkClientTrusted(X509Certificate[] chain, String authType)
        throws CertificateException {
        throw new UnsupportedOperationException();
    }
 
    public void checkServerTrusted(X509Certificate[] chain, String authType)
        throws CertificateException {
        this.chain = chain;
        tm.checkServerTrusted(chain, authType);
    }
    }
 
}
View Code

命令行執行 Java InstallCert maven.aliyun.com      

maven.aliyun.com  按需更換

輸入1,回車,當前文件夾下得到證書文件,將其放入jre/lib/security目錄下,也有的說放在jre\lib\ext 下,只好都放一下試試。

重啟idea,重建maven項目,=一般人就好用了。

然而,我已經快無能為力了。開始懷疑是不是idea的問題?是不是maven3.6.3版本的問題?要不要降個版本?

於是cmd,mvn -v 

  what?

不是內部或外部命令,也不是可運行的程序
或批處理文件。

安裝的時候,明明好用的,環境變量也沒問題,不知道無意間做了什么騷操作。於是刪了maven重裝。

然后在命令行中驗證:mvn help:system

build success!看到本地倉庫中有了文件。但不是在自己創建的本地倉庫repository,而是自行創建了一個repository1.

再從idea上創建,就沒有問題了。


 

對不起大家,我撒謊了,雖然idea中可以使用maven項目,我還是沒能徹底解決   PKIX path building failed:   的問題。

依賴的jar都得手動下載,放到庫中。

https://www.cnblogs.com/fengyupinglan/p/14537223.html

用上面那個方式解決了一半,還是很麻煩?難道因為我用了破解版得idea而懲罰我么?

idea中的解決方法:https://www.cnblogs.com/fengyupinglan/p/14537223.html

 


免責聲明!

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



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