Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Error: Exception in thread "main" java.lang.NoSuchMethodError: org.apache.curator.utils.PathUtils.validatePath(Ljava/lang/String;)Ljava/lang/String;

avatar
Contributor

Hello,

artifact org.apache.curator, version 2.7.1 and higher doesn't work in a spark job.

pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>"test"</name>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>test</id>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.apache.curator</groupId>
      <artifactId>curator-client</artifactId>
      <version>2.7.1</version>
    </dependency>
  </dependencies>
</project>

Source code:

cat src/main/java/com/test/Test.java 
package com.test;

import org.apache.curator.utils.PathUtils;

public class Test {
	public static void main(String[] args) throws Exception {
		PathUtils.validatePath("/tmp");
	}
}

The result is

spark-submit --class com.test.Test --master local test-0.0.1-SNAPSHOT.jar

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.curator.utils.PathUtils.validatePath(Ljava/lang/String;)Ljava/lang/String;
        at com.test.Test.main(Test.java:7)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
        at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
        at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
        at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
        at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

The issue is replicated in spark version 1.6.2 and 2.2.0.2.6.4.0-91. Can you please help to resolve this issue?

1 ACCEPTED SOLUTION

avatar

@Maxim Dashenko

Perhaps when you are packaging your jar file is not adding the curator-client jar correctly to the fat jar.

I tested the following and it works fine:

1. wget http://central.maven.org/maven2/org/apache/curator/curator-client/2.7.1/curator-client-2.7.1.jar

2. spark-shell --jar curator-client-2.7.1.jar

3.

scala> import org.apache.curator.utils.PathUtils;
import org.apache.curator.utils.PathUtils
scala> PathUtils.validatePath("/tmp")

No errors thrown while running the above. You can try adding the --jars and point to the jar file as well and see if that helps.

spark-submit --jars curator-client-2.7.1.jar --class com.test.Test --master local test-0.0.1-SNAPSHOT.jar

Otherwise I suggest you check your fat/uber jar.

HTH

*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.

View solution in original post

5 REPLIES 5

avatar

@Maxim Dashenko

Perhaps when you are packaging your jar file is not adding the curator-client jar correctly to the fat jar.

I tested the following and it works fine:

1. wget http://central.maven.org/maven2/org/apache/curator/curator-client/2.7.1/curator-client-2.7.1.jar

2. spark-shell --jar curator-client-2.7.1.jar

3.

scala> import org.apache.curator.utils.PathUtils;
import org.apache.curator.utils.PathUtils
scala> PathUtils.validatePath("/tmp")

No errors thrown while running the above. You can try adding the --jars and point to the jar file as well and see if that helps.

spark-submit --jars curator-client-2.7.1.jar --class com.test.Test --master local test-0.0.1-SNAPSHOT.jar

Otherwise I suggest you check your fat/uber jar.

HTH

*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.

avatar
Contributor

@Felix Albani thank you for your answer, spark-shell in your sample works because it uses embedded PathUtils artifact:

scala> classOf[PathUtils].getProtectionDomain().getCodeSource().getLocation()
res1: java.net.URL = file:/usr/hdp/2.6.4.0-91/spark/lib/spark-assembly-1.6.3.2.6.4.0-91-hadoop2.7.3.2.6.4.0-91.jar<br>

In my sample I have only one dependency, so the issue can't be caused by the fat jar.

Using --jars curator-client-2.7.1.jar with spark-submit doesn't resolve the issue.

avatar

@Maxim Dashenko sorry about that. The following is working fine:

spark-shell --driver-class-path curator-client-2.7.1.jar
scala> import org.apache.curator.utils.PathUtils;
import org.apache.curator.utils.PathUtils
scala> classOf[PathUtils].getProtectionDomain().getCodeSource().getLocation()
res0: java.net.URL = file:/root/curator-client-2.7.1.jar

Try adding --driver-class-path curator-client-2.7.1.jar to your spark-submit and let me know if it works fine. Also you may want to try using --conf spark.driver.userClassPathFirst=true with the jar and see if that helps.

Thanks!

avatar
Contributor

@Felix Albani using --driver-class-path curator-client-2.7.1.jar for spark-submit has resolved the issue, thank you very much for your help!

avatar

@Maxim Dashenko I'm glad it got resolved. Please take a moment to login and click the "accept" link on the answer!