Randika Isuru
Randika Isuru

Reputation: 81

Why Phantom Cassandra Insert getting "main" java.lang.NoClassDefFoundError: scala/reflect/runtime/package error

I very new to phantom and I have basic knowledge of scala and cassandra. so i am trying to do simple crud example using phantom so i have look at few examples at google. at last i have end up with this example. but I run this code not like as this project readme file said. I just create a intellij project and there is main class like following.

import org.creative.document.dao.impl.{PhantomConnectorExample}
import org.creative.document.database.SongsDatabase
import org.creative.document.entity.Song

object DocumentAPIMain {

   def main(args: Array[String]): Unit = {

      val song = Song(songId,"Wahinnta Athnam gigum di","Pawana","Nanda Malini")

      val songsDatabase = new SongsDatabase(PhantomConnectorExample.connector)
      songsDatabase.saveOrUpdate(song)

   }

}

that was the only chage i have done other than that all the dependencies and everything as like above mention link.

I have created cassandra keyspace, songs table and songs_by_artist table manually. following is show my cassandra shema

CREATE KEYSPACE phantomtest WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}  AND durable_writes = true;

CREATE TABLE phantomtest.songs_by_artist (
artist text,
id timeuuid,
album text,
title text,
PRIMARY KEY (artist, id)
) WITH CLUSTERING ORDER BY (id ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';

CREATE TABLE phantomtest.songs (
id timeuuid PRIMARY KEY,
album text,
artist text,
title text
) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';

After all when i run my main method it will end up with the following error

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: scala/reflect/runtime/package$
at com.outworkers.phantom.column.AbstractColumn.com$outworkers$phantom$column$AbstractColumn$$_name(AbstractColumn.scala:55)
at com.outworkers.phantom.column.AbstractColumn.com$outworkers$phantom$column$AbstractColumn$$_name$(AbstractColumn.scala:54)
at com.outworkers.phantom.column.Column.com$outworkers$phantom$column$AbstractColumn$$_name$lzycompute(Column.scala:22)
at com.outworkers.phantom.column.Column.com$outworkers$phantom$column$AbstractColumn$$_name(Column.scala:22)
at com.outworkers.phantom.column.AbstractColumn.name(AbstractColumn.scala:58)
at com.outworkers.phantom.column.AbstractColumn.name$(AbstractColumn.scala:58)
at com.outworkers.phantom.column.Column.name(Column.scala:22)
at org.creative.document.database.SongsDatabase$anon$macro$1$1.store(SongsDatabase.scala:28)
at org.creative.document.database.SongsDatabase$anon$macro$1$1.store(SongsDatabase.scala:28)
at com.outworkers.phantom.CassandraTable.store(CassandraTable.scala:132)
at org.creative.document.database.SongsDatabase.saveOrUpdate(SongsDatabase.scala:28)
at org.creative.document.main.DocumentAPIMain$.main(DocumentAPIMain.scala:58)
at org.creative.document.main.DocumentAPIMain.main(DocumentAPIMain.scala)
Caused by: java.lang.ClassNotFoundException: scala.reflect.runtime.package$
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)
... 13 more

Please help me to find out the problem. what I have did wrong...

Upvotes: 0

Views: 350

Answers (1)

Mahesh Chand
Mahesh Chand

Reputation: 3250

I faced the same issue and added the following dependency.

"org.scala-lang" % "scala-reflect" % scalaVersion.value

It worked for me.

Upvotes: 2

Related Questions