自定义SSLSocketFactory时ClassNotFoun

自定义SSLSocketFactory时ClassNotFoun

本文介绍了使用自定义SSLSocketFactory时ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义SSLSocketFactory类并将其设置如下

I have created a custom SSLSocketFactory class and set it as below

ldapEnv.put(Context.SECURITY_PROTOCOL, "ssl");
ldapEnv.put(FACTORY_SOCKET, socketFactoryClass);

LdapContext ldapContext = new InitialLdapContext(ldapEnv, null);

从Eclipse Dev Environment运行并从命令提示符运行它作为Jar文件时,它工作正常。但是当我将其包装在服务包装器中并将其作为Windows服务启动时,它不起作用。我得到以下异常,

It works fine when running from Eclipse Dev Environment, and running it as Jar file from command prompt. But it doesn't work when I wrap it inside a service wrapper and launch it as Windows Service. I get the following exception,

javax.naming.CommunicationException: 192.168.100.22:636 [Root exception is java.lang.ClassNotFoundException: com/testing/diraccess/service/ActiveDirectory$TestSSLFactory]
at com.sun.jndi.ldap.Connection.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapClient.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapClient.getInstance(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.connect(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(Unknown Source)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.ldap.InitialLdapContext.<init>(Unknown Source)

Caused by: java.lang.ClassNotFoundException: com/testing/diraccess/service/ActiveDirectory$TestSSLFactory
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.jndi.ldap.VersionHelper12.loadClass(Unknown Source)
at com.sun.jndi.ldap.Connection.createSocket(Unknown Source)
... 35 more

任何帮助???

推荐答案

这是一个很久以来我发布了这个问题。由于这篇文章没有任何答案,似乎也得到了一些观点,我想我可以分享我最后解决的问题(我已经在几年前的问题的评论部分发布了这个)。

It's been a very long time since I posted this question. Since this post doesn't have any answers and also seems to be getting some views, I thought I could share what I did then to resolve it finally (I had already posted this in comments section of the question years ago).

我能够通过使用 -Xbootclasspath / a:选项将该jar文件包含在引导加载程序类路径中来解决此问题。但我还是不喜欢这个解决方案。

I was able to resolve this issue by including that jar file in boot loader class path using -Xbootclasspath/a: option. But I didn't like this solution anyway.

这篇关于使用自定义SSLSocketFactory时ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:02