question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When java -jar execute, JavaEsSpark.esRDD raise ExceptionInInitializerError

See original GitHub issue

What kind an issue is this?

  • [ * ] Bug report. If you’ve found a bug, please provide a code snippet or test to reproduce it below.
    The easier it is to track down the bug, the faster it is solved.
  • Feature Request. Start by telling us what problem you’re trying to solve.
    Often a solution already exists! Don’t send pull requests to implement new features without first getting our support. Sometimes we leave features out on purpose to keep the project small.

Issue description

I am developing part of spark (v2.4.3) which reads elasticsearch (v7.3.0) on spring-boot 2 (web) using es-hadoop (v7.3.1).

** ref https://www.elastic.co/guide/en/elasticsearch/hadoop/master/spark.html

When I run it with “mvn spring-boot:run” it works fine.

But, When I run it with “java -jar output.jar”, JavaEsSpark make error about accessing elasticsearch. I thought in many ways but I don’t know why.

“ExceptionInInitializerError: null … RestService” “sql.DefaultSource15 could not be instantiated” “URI is not a hierarchical … version.”

I ask for your help (-.-)

** ps. I checked packages in jar file. => OK. I tried with SparkSession, but also fail. (java -jar execution)

** my code https://github.com/maxmin93/agens-spark/blob/master/src/main/java/net/bitnine/agensspark/AgenssparkApplication.java

Steps to reproduce

Code:

LOGGER.info("SpringBootSpark To Elasticsearch Application: {}, {}, {}, {}"
                , appName, nodes, port, sparkHome);

String master = "local[*]";
SparkConf conf = new SparkConf()
        .setAppName(appName)
        .setSparkHome(sparkHome)
        .setMaster(master)
                .set("spark.executor.memory", "2g")
        .set("spark.driver.memory", "2g")
        .set("spark.eventLog.enabled","false")
        .set("es.nodes.wan.only", "true")
        .set("es.nodes", nodes)
        .set("es.port", port)
        .set("es.mapping.id", "id")
        .set("es.write.operation", "upsert")
        .set("es.index.read.missing.as.empty", "true");

        JavaSparkContext jsc = new JavaSparkContext(conf);

// for DEBUG
System.out.println("\n\n==================================\n");
System.out.println(Arrays.stream(jsc.getConf().getAll()).map(t->{
    return t._1()+"="+t._2();
}).collect(Collectors.joining(", ")));

JavaPairRDD<String, Map<String, Object>> esRDD =
    JavaEsSpark.esRDD(jsc, resource, "?q=datasource:sample");
System.out.println("\n**count = "+esRDD.count());

Strack trace:

java.lang.ExceptionInInitializerError: null
	at org.elasticsearch.hadoop.rest.RestService.findPartitions(RestService.java:216) ~[elasticsearch-hadoop-7.3.1.jar!/:7.3.1]
	at org.elasticsearch.spark.rdd.AbstractEsRDD.esPartitions$lzycompute(AbstractEsRDD.scala:79) ~[elasticsearch-hadoop-7.3.1.jar!/:7.3.1]
	at org.elasticsearch.spark.rdd.AbstractEsRDD.esPartitions(AbstractEsRDD.scala:78) ~[elasticsearch-hadoop-7.3.1.jar!/:7.3.1]
	at org.elasticsearch.spark.rdd.AbstractEsRDD.getPartitions(AbstractEsRDD.scala:48) ~[elasticsearch-hadoop-7.3.1.jar!/:7.3.1]
	at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:253) ~[spark-core_2.11-2.4.3.jar!/:2.4.3]
...
Caused by: java.lang.IllegalArgumentException: URI is not hierarchical
	at java.io.File.<init>(File.java:418) ~[na:1.8.0_121]
	at org.elasticsearch.hadoop.util.IOUtils.toCanonicalFilePath(IOUtils.java:242) ~[elasticsearch-hadoop-7.3.1.jar!/:7.3.1]
	at org.elasticsearch.hadoop.util.Version.<clinit>(Version.java:66) ~[elasticsearch-hadoop-7.3.1.jar!/:7.3.1]
	... 27 common frames omitted

Version Info

OS: : MacOS lastest JVM : 1.8 Hadoop/Spark: null/2.4.3 ES-Hadoop : 7.3.1 ES : 7.3.0

Feature description

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
maxmin93commented, Sep 25, 2019

I try as your advice.

jar -tf target/agensspark-0.0.1-SNAPSHOT.jar | grep elastic ==> Nothing

java -jar target/agensspark-0.0.1-SNAPSHOT.jar -cp ~/Servers/es-hadoop/dist/elasticsearch-hadoop-7.3.1.jar ==> Caused by: java.lang.ClassNotFoundException: org.elasticsearch.spark.rdd.api.java.JavaEsSpark

Uhm… like some kind of difficult

Let’s go ahead with “mvn spring-boot:run” and look again after the bug-fix. Thank (^^)

<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch-hadoop</artifactId>
    <version>${es-hadoop.version}</version>
    <scope>provided</scope>
</dependency>
...
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch-hadoop</artifactId>
            </exclude>
        </excludes>
    </configuration>
</plugin>
0reactions
carlose2108commented, Oct 28, 2020

Hi there!

Any help with this?

Error message: " java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.hadoop.util.Version at org.elasticsearch.hadoop.rest.RestService.createWriter(RestService.java:577) at org.elasticsearch.spark.rdd.EsRDDWriter.write(EsRDDWriter.scala:65) at org.elasticsearch.spark.rdd.EsSpark$$anonfun$doSaveToEs$1.apply(EsSpark.scala:108) at org.elasticsearch.spark.rdd.EsSpark$$anonfun$doSaveToEs$1.apply(EsSpark.scala:108) at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90) at org.apache.spark.scheduler.Task.run(Task.scala:127) at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:444) at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1377) at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:447) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)"

My code is:

val ss: SparkSession = SparkSession
                .builder()
                .appName("WriteToES")
                .getOrCreate()

val esConf = Map("es.nodes" -> "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.es.amazonaws.com", 
                         "es.port" -> "443",
                         "es.net.http.auth.user" -> "xxxxxxxxx",
                         "es.net.http.auth.pass" -> "xxxxxx",
                         "es.nodes.discovery" -> "true",
                         "es.index.auto.create" -> "true",
                         "es.nodes.wan.only" -> "true",
                         "es.net.ssl" -> "true"
                         )

        Kinesis.buildStream(ssc, stream, credentials)
            .map(Gzip.decompress)
            .flatMap(Strings.bytesToStringLines)
            .transform(Json.jsonToZabbixTypes[ZabbixItemInteger](_))
            .transform(rdd => {
               EsSpark.saveToEs(rdd, "spark/docs", esConf)
                rdd                
            })

Spark-submit:

spark-submit \
       	--name KinesisGzipElastic \
       	--class Main \
       	--master local[*] \
        --deploy-mode client \
        --packages org.apache.spark:spark-streaming-kinesis-asl_2.12:3.0.0,org.elasticsearch.client:elasticsearch-rest-high-level-client:7.7.0 \
        trkinesisgzipelastic_2.12-0.1.0-SNAPSHOT.jar

This situation is very frustrated.

Hope you can help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

When executing JAR, get ExceptionInInitializerError: version ...
I've been writing a small project in Eclipse which runs perfectly within the IDE. Then I've build a runnable .jar file through Eclipse...
Read more >
Solved: Getting "Caused by: java.lang.NoClassDefFoundError...
Hello Community,. I'm running into a problem when I submit a job in Hue editor, from Hue home page I navigate to Query...
Read more >
当java-jar执行时,javaesspark.eSrdd引发 ... - 编程技术网
When java -jar execute, JavaEsSpark.esRDD raise ExceptionInInitializerError. 这个问题是什么? [ * ] Bug report. If you've found a bug, ...
Read more >
Resolve the "java.lang.ClassNotFoundException" in Spark on ...
This error occurs when either of the following conditions is true: The spark-submit job can't find the relevant files in the class path....
Read more >
JAR File Overview
What is JAR? JAR stands for Java ARchive. It's a file format based on the popular ZIP file format and is used for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found