sbt failure for java.sql.{Connector,DriverManager,ResultSet} - scala

I am running into an issue when I run "sbt package" on a scala program. Here are the imports that I have in my scala program
import java.sql.{Connecion,DriverManager,ResultSet}
when I run sbt package, I get the below errors.
[error] /home/SriniNN/scala_cd/ReadDJDBC/src/main/scala/ReadDJDBC.scala:8: object Connecion is not a member of package java.sql
[error] import java.sql.{Connecion,DriverManager,ResultSet}
[error] ^
[error] /home/SriniNN/scala_cd/ReadDJDBC/src/main/scala/ReadDJDBC.scala:26: value getConnecion is not a member of object java.sql.DriverManager
[error] val jdbcRDD = new JdbcRDD(sc, () => DriverManager.getConnecion(url,username,password),
This is what I have in my build.sbt
name:= "ReadJDBC"
version:= "1.0"
scalaVersion:= "2.11.8"
libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "1.6.2"
Can you please help me resolve this issue?

You are just mis-spelling Connection. Note the t between the c and i. If you fix that typo then it should work

Related

Play Framework: [Error] object inject is not a member of package javax

My play framework application is all of a sudden throwing the following errors during compilation:
[error] /Users/ihorton/Client Work/DPaaS/coursera-scala/cookbook/app/controllers/HomeController.scala:5:14: object inject is not a member of package javax
[error] import javax.inject._
[error] ^
[error] /Users/ihorton/Client Work/DPaaS/coursera-scala/cookbook/app/controllers/HomeController.scala:11:2: trait Singleton is abstract; cannot be instantiated
[error] #Singleton
[error] ^
[error] /Users/ihorton/Client Work/DPaaS/coursera-scala/cookbook/app/controllers/HomeController.scala:12:23: not found: type Inject
[error] class HomeController #Inject()(controllerComponents: ControllerComponents) extends AbstractController(controllerComponents) {
[error] ^
^
Here is my use of javax.inject, #Inject and #Singleton in code:
import javax.inject._
#Singleton
class RecipeController #Inject()(controllerComponents: ControllerComponents) extends AbstractController(controllerComponents) {
...
I've read through what looks to be the same issue here, but trying sbt reload prior to compile doesn't work for me.
What's puzzling, unless I'm misreading the Play Framework 2.8.x documentation, is that it seems like javax.inject should be packaged with Play out of the box. So I'm not sure why this object would be missing.
I'm using the following versions:
Play: 2.8.8
Scala: 2.13.6
JDK: 17.0.1
Here's my build.sbt file to which I've added javax.inject which doesn't seem to resolve the issue.
name := """cookbook"""
organization := "com.ian-horton"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.13.6"
libraryDependencies ++= Seq(
guice,
"commons-io" % "commons-io" % "2.5",
"javax.inject" % "javax.inject" % "1",
"net.sourceforge.tess4j" % "tess4j" % "5.0.0",
"org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test,
"org.specs2" %% "specs2-core" % "4.13.0" % Test)
Happy to provide additional detail if need be.
Thanks in advance!
Update
Finding this other Stack Overflow Question I followed the steps manually added the Maven dependency for Javax.Inject to my project in Intellij which fixed the problem.
I'm keeping this question open though in the hopes that someone can perhaps shed some light on why this dependency isn't pulled in with Play.

scala error: bad symbolic reference

I was using sbt to compile a scala code, and got the following error message
[error] /user/xyin/Projects/measurement_wspark/src/main/scala/json2csv.scala:41: bad symbolic reference. A signature in DefaultReads.class refers to term time
[error] in package java which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling DefaultReads.class.
[error] val ts = (json \ "RequestTimestamp").validate[String]
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
I was using the play json library to parse json files in my main class. And the content of the build.sbt file is like the following:
name := "json_parser"
version := "1.0"
scalaVersion := "2.10.1"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.6.1"
resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.4.8"
I am totally new to scala and the play framework. Does anyone has any clue about this problem? Thanks!

Why does sbt say "bad symbolic reference..." for test with ScalaTest?

I started using ScalaTest with sbt. The build.sbt is as follows:
name := "MySpecSample"
version := "1.0"
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.0" % "test"
scalaVersion := "2.10.3"
Initial test code is here. This test code runs alone without main component code.
import collection.mutable.Stack
import org.scalatest._
class ExampleSpec extends FlatSpec with Matchers {
"A Stack" should "pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
stack.pop() should be (2)
stack.pop() should be (1)
}
it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[Int]
a [NoSuchElementException] should be thrownBy {
emptyStack.pop()
}
}
}
I wrote it according to Official quick start.
But it doesn't work properly. The error message is as follows:
> test
[info] Compiling 1 Scala source to /Users/kaisasak/untitled/target/scala-2.10/test-classes...
[error] bad symbolic reference. A signature in package.class refers to type compileTimeOnly
[error] in package scala.annotation which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling package.class.
[error] /Users/kaisasak/untitled/src/test/scala/ExampleSpec.scala:6: Reference to class FlatSpec in package scalatest should not have survived past type checking,
[error] it should have been processed and eliminated during expansion of an enclosing macro.
[error] class ExampleSpec extends FlatSpec with Matchers {
[error] ^
[error] two errors found
[error] (test:compile) Compilation failed
[error] Total time: 3 s, completed Jun 29, 2014 11:20:41 AM
I can find same problems on Google but no good answer was available.
My environment is here.
MacOSX 10.9.3
Scala 2.10.3
sbt 0.13.2
I tried with sbt 0.13.1 after downgrading, but the result is the same to the one of 0.13.2. What should I do to use ScalaTest with sbt?
In your build.sbt you set the version of Scala to 2.10.3 with the following:
scalaVersion := "2.10.3"
However the ScalaTest dependency uses Scala 2.11 explicitly (note the _2.11 part):
"org.scalatest" % "scalatest_2.11" % "2.2.0" % "test"
You have to use the same major scala version for both.
With sbt you can simply ensure this using %% instead of % as follows:
"org.scalatest" %% "scalatest" % "2.2.0" % "test"

Scala not working with heroku example

I'm following a tutorial to create a scala web app with Heroku here: https://devcenter.heroku.com/articles/scala
I've copied there example exactly, but when I run
sbt clean compile stage
It fails to compile because of these errors:
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:1: object jboss is not a member of package org
[error] import org.jboss.netty.handler.codec.http.{HttpRequest, HttpResponse}
[error] ^
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:2: object twitter is not a member of package com
[error] import com.twitter.finagle.builder.ServerBuilder
[error] ^
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:3: object twitter is not a member of package com
[error] import com.twitter.finagle.http.{Http, Response}
[error] ^
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:4: object twitter is not a member of package com
[error] import com.twitter.finagle.Service
[error] ^
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:5: object twitter is not a member of package com
[error] import com.twitter.util.Future
[error] ^
[error] 5 errors found
Basically, I think it has to do with finagle not being available or not in the packages I have or something. However, I have no idea how to install finagle and there are neither instructions in the tutorial above nor at https://github.com/twitter/finagle
What can I do to get this to compile?
If will depend on the version of Scala and Finagle you want to use, but to add Finagle to the project, just add the following to build.sbt
libraryDependencies += "com.twitter" % "finagle-core_2.9.1" % "1.11.0" exclude("org.apache.thrift", "libthrift")
libraryDependencies += "com.twitter" % "finagle-http_2.9.1" % "1.11.0"
libraryDependencies += "com.twitter" % "finagle-serversets_2.9.1" % "1.11.0" excludeAll(
ExclusionRule(organization = "com.sun.jdmk"),
ExclusionRule(organization = "com.sun.jmx"),
ExclusionRule(organization = "javax.jms")
)
This example is about 3 months old, so I'm sure you can get a newer version of Finagle.
I tried the code and it worked for me. Perhaps see if the source on GitHub works: https://github.com/heroku/devcenter-scala

sbt failed to compile "import ch.epfl.lamp.fjbg._"

scalac is successed to compile this code.
import ch.epfl.lamp.fjbg._
But sbt(0.11.2) is failed to compile it.
[error] genbytecode.scala:2: not found: object ch
[error] import ch.epfl.lamp.fjbg._
[error] ^
[error] one error found
Why and how can I fix this?
The OP posted a comment:
I create build.sbt and write libraryDependencies += "org.scala-lang" % "scala-compiler" % "2.9.1" work it! thank you.