1.Slf4J-API版本兼容

问题描述

Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;

最后发现是slf4j的版本不对, 他使用的是slf4j-api-2.0.99.jar

但是,但是,官方正式版只有1.6.1,而且至今我都没发现有2.0.x系列的计划呢!! 我的神啊,哪里来的版本? 经提醒,这个jar就在 1.6.1版的发行包中!! slf4j-1.6.1.zip\slf4j-1.6.1\integration\lib

神奇啊,为啥呢?? 找不到其源码jar,好吧,上JD-GUI,看看报错的类MessageFormatter.arrayFormat 2.0.99版的方法声明:

public static final String arrayFormat(String messagePattern, Object[] argArray)

1.6.1版的方法声明:

public static final FormattingTuple arrayFormat(String messagePattern, Object[] argArray)

看到区别了吧,返回值的类型不同了!同样的,还有一个1.6.99版的API,内容与2.0.99版一致

继续追查, 看Slf4j源码仓库的一个提交:https://github.com/ceki/slf4j/commit/581b20f8aaa140ce722669a2cf1d8582a963ff4e 里面的comments是: `

- fixed bug 154

It is expected that all SLF4J releases in the 1.6.x and 2.0.x series will be mutually compatible. Note that the 2.0.x series is expected to require JDK 1.5 or later. `

兼容旧版本?? 明显就是不兼容嘛! 但 bug 154 到底是什么内容呢?

几经查找,终于找到其issue系统的地址,是个bugzilla呢 -- 天啊,官网一个网站,下载一个网站,源码管理一个网站,issue管理又是再一个网站?!!

http://bugzilla.slf4j.org/show_bug.cgi?id=154 但内容感觉与 2.0.x无关呢.

解决方案

将slf4j升级到1.6.5以上。

2.解决PKIX:unable to find valid certification path to requested target 的问题

这两天在twitter服务器上忽然遇到这样的异常:

e: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

经过检查确认,完整的异常信息应该如下:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

后来到twitter开发者网站上去看到了也有人遇到了类似的问题,链接如下:https://dev.twitter.com/discussions/533

但是都没说明具体的解决方法,郁闷啊!!

在oracle某一博客上说是可以这样解决的:http://blogs.oracle.com/gc/entry/unable_to_find_valid_certification

但是悲催的是那个Java类已经无法下载了。。。。历经N次的google,终于找到该文件了,不敢独享,记录于此。

问题的根本是:

缺少安全证书时出现的异常。

解决问题方法:

将你要访问的webservice/url....的安全认证证书导入到客户端即可。

以下是获取安全证书的一种方法,通过以下程序获取安全证书(记得根据需求修改部分代码):

package com.company;

import javax.net.ssl.*;
import java.io.*;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; public class InstallCert { private final static String PRODUCTION_HOST = "gateway.push.apple.com";
private final static int PRODUCTION_PORT = 2195;
private final static String DEVELOPMENT_HOST = "gateway.sandbox.push.apple.com";
private final static int DEVELOPMENT_PORT = 2195; private static String CLIENT_KEY_STORE = "C:\\myfile\\certificates\\pair1\\push-pro1-123456.p12"; public static void main(String[] args) throws Exception { String host;
int port;
host = DEVELOPMENT_HOST;
port = DEVELOPMENT_PORT;
String passwd = "123456"; File file = new File(CLIENT_KEY_STORE);
System.out.println("Loading KeyStore " + file + "...");
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream(file), passwd.toCharArray()); 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("Server sent " + chain.length + " certificate(s):");
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("apnssandbox.p12");
ks.store(out, passwd.toCharArray());
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);
}
} }

输入1,回车,然后会在当前的目录下产生一个名为“ssecacerts”的证书。

将证书拷贝到$JAVA_HOME/jre/lib/security目录下,或者通过以下方式:
System.setProperty("javax.net.ssl.trustStore", "你的jssecacerts证书路径");

3.

Maven在部署(deploy)的时候会报错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project ams-httpdns: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help ]
[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 ] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

JAVA错误汇总的更多相关文章

  1. java 错误汇总

    一.怎么处理警告:编码 GBK 的不可映射字符 解决办法是:应该使用-encoding参数指明编码方式:javac -encoding UTF-8 XX.java,这下没警告了,运行也正确了在JCre ...

  2. (转)JAVA排序汇总

    JAVA排序汇总 package com.softeem.jbs.lesson4; import java.util.Random; /** * 排序测试类 * * 排序算法的分类如下: * 1.插入 ...

  3. android studio 错误汇总以及解决办法

    android studio 错误汇总以及解决办法  参考 https://www.jianshu.com/p/7c7de6562231 问题1. Error:Execution failed for ...

  4. Entity Framework学习笔记——错误汇总

    之前的小项目做完了,到了总结经验和更新学习笔记的时间了.开始正题之前先啰嗦一下,对之前的学习目标进行一个调整:“根据代码生成表”与“生成数据库脚本和变更脚本”合并为“Code First模式日常使用篇 ...

  5. 李洪强iOS开发之OC常见错误汇总

    // //  main.m //  16 - 常见错误汇总 // //  Created by vic fan on 16/7/13. //  Copyright © 2016年 李洪强. All r ...

  6. Python常见的错误汇总

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 错误: [错误分析]第二个参数必须为类,否则会报TypeError,所以正确的应 ...

  7. Java设计模式汇总

    Java设计模式汇总 设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接模式. ...

  8. 基于Windows下处理Java错误:编码GBK的不可映射字符的解决方案

    基于Windows下处理Java错误:编码GBK的不可映射字符的解决方案 最近在研究Java,涉及命令行编译,使用notepad++编辑器,然后使用javac编译: 之前的几个文件没有中文的内容,都没 ...

  9. 【转】JAVA错误:The public type *** must be defined in its own file***

    出现The public type xxx must be defined in its own file这个问题,是由于定义的JAVA类同文件名不一致.public类必须定义在它自己的文件中. 解决 ...

随机推荐

  1. hadoop2.2编程:MRUnit测试

    引用地址:http://www.cnblogs.com/lucius/p/3442381.html examples: Overview This document explains how to w ...

  2. 我的ORM汇总

    MyOql是我写的ORM,目前仅支持 MSSql2005+ ,从2009年到今天,已使用过不少项目,之后会写 其它关系数据库的解析器: MySql,Sqlite,Oracle 等. 代码地址(最新版) ...

  3. 你写的Try...Catch真的有必要么?

    很多人喜欢用Try...Catch把每一个方法都包裹起来,可是真的有必要么? 为什么要这样做?我估计是大家被BUG吓怕了,生怕生产环境出现各种莫名其妙的错误,比如最经典的NullReferenceEx ...

  4. Scrum Guide - Scrum指南中文版

    现在公司在使用敏捷开发模式进行日常的开发和管理工作,所以我看了下Ken Schwaber的<Scrum Guide>这本小册子,原本是英文的,这里提供中文的,以供日后复习和参考. Scru ...

  5. 用.NET MVC实现长轮询,与jQuery.AJAX即时双向通信

    两周前用长轮询做了一个Chat,并移植到了Azure,还写了篇博客http://www.cnblogs.com/indream/p/3187540.html,让大家帮忙测试. 首先感谢300位注册用户 ...

  6. Git Shell 基本命令(官网脱水版)

    用户信息 当安装完 Git 应该做的第一件事就是设置你的用户名称与邮件地址. 这样做很重要,因为每一个 Git 的提交都会使用这些信息,并且它会写入到你的每一次提交中,不可更改: $ git conf ...

  7. Azure Table storage 基本用法 -- Azure Storage 之 Table

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table,其中的 Table 就是本文的主角 Azure Tabl ...

  8. Java针对数据库增删改查代码

    package com.bank.abc; import java.beans.PropertyVetoException; import java.sql.Connection; import ja ...

  9. VMware Workstation and Hyper-V are not compatible. 解决方案

    VMware 和 Hyper-V 不能共存问题报错如下:VMware Workstation and Hyper-V are notcompatible. Remove the Hyper-V rol ...

  10. LINQ系列:LINQ to SQL Where条件

    1. 单一条件查询 var expr = context.Products .Where(p => p.ProductName == "LINQ to SQL"); SELE ...