Connect ZK
public static void main(String[] args) {
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("127.0.0.1")
.retryPolicy(new RetryOneTime( 4))
.connectionTimeoutMs(10000)
.sessionTimeoutMs(6000)
.build();
curator.start();
}
Error Messages:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/curator/RetryPolicy
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.curator.RetryPolicy
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
… 7 more
To solve it, it is not suitable for the execution of the main method, just use the following method
@Test
public void testzk() {
CuratorFramework curatorFramework = Demo.getCuratorFramework();
System.out.println(curatorFramework);
}
public static CuratorFramework getCuratorFramework() {
CuratorFramework client = CuratorFrameworkFactory.builder().connectString("127.0.0.1:2181")
.connectionTimeoutMs(60 * 1000)
.sessionTimeoutMs(60 * 1000).retryPolicy(new RetryUntilElapsed(1000, 4)).build();
client.start();
return client;
}
Read More:
- [Solved] Error: A JNI error has occurred, please check your installation and try again Exception in thread
- [Solved] Eclipse Error: A JNI error has occurred, please check your installation and try again
- [Solved] Error: A JNI error has occurred, please check your installation and try again
- [Solved] JAVA Error: Error:A JNI error has occurred,please check your installation and try again
- OTA Pack Compile Error: ExternalError: Failed to run signapk.jar: return code 1:Error: A JNI error has occurred
- JNI ERROR (2354): JNI connection is NULL [How to Solve]
- ZK Error contacting service. It is probably not running [How to Solve]
- How to Solve JAVA Error: error: A JNI error has occureed
- How to Solve classnotfoundexception error in spark without Hadoop runtime
- [Solved] Linux java -jar Start Project Error: Unsupported major.minor version 52.0
- [Solved] Rocketmq installation error: org.apache.rocketmq.remoting.exception.remotingconnectexception: connect to failed
- [Solved] Project Startup Error: Redis health check failed:Unable to connect to localhost6379
- [Solved] Project Startup Error: Redis health check failed: Unable to connect to localhost6379
- Springboot WARNING: An illegal reflective access operation has occurred
- Eclipse Error: Could not create the Java Virtual Machine Error:A fatal exception has occurred
- [Solved] Unable to connect to a as user root com.jcraft.jsch.JSchException: Auth failUnable to connect
- [Solved] Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred.
- [Solved] javajdk1.8 Run javaFx Error: Error:Error: A fatal exception has occurred. Unrecognized option: –module-path
- [Solved] Jedis connect and operate Redis error: Failed to create socket和connect timed out
- [Solved] ES Error: Elasticsearch health check failed