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

 

posted @ 2021-03-03 12:10  少时也曾爱白衣  阅读(3941)  评论(0编辑  收藏  举报