Scalc SBT compile failing - scala

I am trying to follow code from below link
http://spark.apache.org/docs/latest/quick-start.html
But when I am trying to create package it is failing. I want to know 2 thinks
obviously, why it is failing
why it is showing older version of the scala, while I mentioned 2.11
Below is the error message.
[info] Set current project to default-0464ce (in build file:/home/ubuntu/simple_sbt/)
[info] Updating {file:/home/ubuntu/simple_sbt/}default-0464ce...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to /home/ubuntu/simple_sbt/target/scala-2.9.1/classes...
[error] /home/ubuntu/simple_sbt/src/main/scala/SimpleApp.scala:1: object apache is not a member of package org
[error] import org.apache.spark.SparkContext
[error] ^
[error] /home/ubuntu/simple_sbt/src/main/scala/SimpleApp.scala:2: object apache is not a member of package org
[error] import org.apache.spark.SparkContext._
[error] ^
[error] two errors found
[error] {file:/home/ubuntu/simple_sbt/}default-0464ce/compile:compile: Compilation failed
[error] Total time: 2 s, completed Aug 30, 2016 3:19:18 AM

when you run sbt package , sometimes it fails as there are no dependencies that are downloaded and will be resolved for the files imported.
Try running, sbt run first and then sbt package . sbt run should bring in all the dependencies on top of which packaging and compiling will be possible.
If the above does not solves your problem, you need to share your sbt build file and the environment that you are using. In which directory you are running these commands, will also play a role.

Related

How to correctly prepare and setting preloaded sbt lib

In my situation, I cannot access internet in my office linux server. Therefore, I installed sbt in my personal computer. I followed instructions on sbt official web-site and run/compile a "hello world" for getting all dependency data.
Then, I copied ~/.ivy2 and ~/.sbt and sbt bin folders to my offline office desktop. But when I run sbt, I got these errors:
[info] welcome to sbt 1.4.9 (Oracle Corporation Java 1.8.0_25)
[info] loading project definition from /proj/mtk07847/test/scala/project
[info] Updating
[info] Resolved dependencies
[warn]
[warn] Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading org.scala-lang:scala-library:2.12.12
[error] Not found
[error] Not found
[error] download error: Caught java.net.SocketException: Connection reset (Connection reset) while downloading https://repo1.maven.org/maven2/org/s
cala-lang/scala-library/2.12.12/scala-library-2.12.12.pom
[error] not found: ~/.ivy2/localorg.scala-lang/scala-library/2.12.12/ivys/ivy.xml
...
It seems that sbt tried to download missing scala-library:2.12.12 which I already prepared.
In my ~/.ivy2 folder,the structure and path looks like the following:
~/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.12.jar
~/.ivy2/cache/org.scala-lang/scala-library/ivy-2.12.12.xml
~/.ivy2/cache/org.scala-lang/scala-library/ivy-2.12.12.xml.original
~/.ivy2/cache/org.scala-lang/scala-library/ivydata-2.12.12.properties
which is different from above messages:
[error] not found: ~/.ivy2/localorg.scala-lang/scala-library/2.12.12/ivys/ivy.xml
should I modified any describing files to indicate searching path or rule for sbt? or this method
is totally wrong (if so, can anyone know the flow guide me the better way?)

Scalatra - not found: object scalate

Context: I'm looking to pick up Scalatra for the first time. I'm following instructions from Scalatra In Action as well as the sample code repo provided. I'm able to get a template project created using g8. When I update the code in the PageController file and start the jetty server I get some really strange error messaging, see below.
c:\Users\eric.barnes\Desktop\scalatra-cms>sbt
[info] welcome to sbt
1.4.5 (Oracle Corporation Java 16.0.2)
[info] loading global plugins from C:\Users\eric.barnes\.sbt\1.0\plugins
[info] loading settings for project scalatra-cms-build from plugins.sbt ...
[info] loading project definition from C:\Users\eric.barnes\Desktop\scalatra-cms\project
[info] loading settings for project hello from build.sbt ...
[info] set current project to Scalatra CMS (in build
file:/C:/Users/eric.barnes/Desktop/scalatra-cms/)
[info] sbt server started at local:sbt-server-dc962f233e7070ae620d
[info] started sbt server sbt:Scalatra CMS> ~jetty:start [info] compiling 1 Scala source to
C:\Users\eric.barnes\Desktop\scalatra-cms\target\scala-2.13\classes ...
[error] C:\Users\eric.barnes\Desktop\scalatra-
cms\src\main\scala\com\example\cms\PageController.scala:4:8: not found: object scalate
[error] import scalate.ScalateSupport [error] ^
[error] C:\Users\eric.barnes\Desktop\scalatra-
cms\src\main\scala\com\example\cms\PageController.scala:6:31: not found: type
ScalatraCmsStack [error] class PagesController extends ScalatraCmsStack {
[error] ^
[error] C:\Users\eric.barnes\Desktop\scalatra-
cms\src\main\scala\com\example\cms\PageController.scala:8:3: not found: value get
[error] get("/pages/:slug") {
[error] ^
[error] C:\Users\eric.barnes\Desktop\scalatra-
cms\src\main\scala\com\example\cms\PageController.scala:9:5: not found: value contentType
[error] contentType="text/html"
[error] ^
[error] C:\Users\eric.barnes\Desktop\scalatra-
cms\src\main\scala\com\example\cms\PageController.scala:10:35: not found: value params
[error] PageDao.pages find (_.slug == params("slug")) match {
[error] ^
[error] C:\Users\eric.barnes\Desktop\scalatra-
cms\src\main\scala\com\example\cms\PageController.scala:11:26: not found: value ssp
[error] case Some(page) => ssp("/pages/show", "page" -> page)
[error] ^
[error] 6 errors found [error] (Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed Oct 4, 2021, 10:51:45 AM [info] 1. Monitoring source files
for hello/jetty:start... [info] Press <enter> to interrupt or '?' for more options.
Questions: The error messaging here is a little confusing for a first time Scalatra user. I'm using the same code in the PageController repo so why am I seeing these errors and how can I resolve them? It looks like my shell doesn't recognize the scalate library as an existing library but it's my understanding scalate comes packages with scalatra on install so I'm quite confused.
You have to add the following dependency to your build file to use Scalate (which is a template engine in Scala) in your Scalatra project:
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion
You can see the build configuration of the Sample project at: https://github.com/scalatra/scalatra-in-action/blob/master/chapter02/project/build.scala
By the way, Scalatra in Action is a little old book based on Scalatra 2.4 while the latest major version of Scalatra 2.8. Though most of topics in the book are still effective for Scalatra 2.8, Scalate support has been deprecated in Scalatra 2.8. We recommend using Twirl instead of Scalate in Scalatra 2.8.

object scalatest is not a member of package org [error] Cygwin

I was wondering if I could get some help with this one. I know there are many different issues with the same title, however, after following all the instructions (I hope), I could not get it to compile still. I've been at this for over 7 hours.
This is my issue. I am using Cygwin64 terminal to do some scala programming with sbt. I run the test and make sure that the test file is in the test folder but nothing is working. I have tried to compile it without the test file and then bring it back in but it does not work either.
$ sbt test
[info] Loading project definition from C:\cygwin64\home\Sam\hof\project
[info] Set current project to hof (in build file:/C:/cygwin64/home/Sam/hof/)
[info] Compiling 1 Scala source to C:\cygwin64\home\Sam\hof\target\scala-2.10\test-classes...
[error] C:\cygwin64\home\Sam\hof\src\test\scala\TestSuite.scala:3: object scalatest is not a member of package org
[error] class TestSuite extends org.scalatest.FunSuite {
[error] ^
[error] C:\cygwin64\home\Sam\hof\src\test\scala\TestSuite.scala:5: not found: value test
[error] test("map2 with add"){
[error] ^
[error] two errors found
[error] (test:compileIncremental) Compilation failed
[error] Total time: 3 s, completed Sep 19, 2016 1:07:10 AM
Is there anything I can do?
I had the same problem. Running sbt test in the project root gave me the object scalatest is not a member of package org error. But when I changed to src/test directory, it completed successfully.

How to include a library on bintray in Scala Maven project

I'm making a project in Scala (2.11), using Maven as my build tool. I'd like to use this library, but I can't get it to work.
I have a minimal (2 files) example repository here: https://github.com/evertheylen/scala-maven-bintray-example
I added two dependencies, kafka and scala-kafka-client. Both times I followed the instructions on their respective websites, but the last one (from bintray) is giving me problems. I would like the repository to be defined in the project, and not in my personal settings.xml (though I did try that and it didn't work).
The error given to me by mvn package exec:java -Dexec.mainClass=be.evertheylen.SampleApplication is:
[ERROR] .../src/main/scala/SampleApplication.scala:3: error: not found: object cakesolutions
[ERROR] import cakesolutions.kafka.KafkaProducer
[ERROR] ^
[ERROR] .../src/main/scala/SampleApplication.scala:4: error: not found: object cakesolutions
[ERROR] import cakesolutions.kafka.KafkaProducer.Conf
[ERROR] ^
[ERROR] two errors found
Although mvn dependency:list does in fact list the library:
[INFO] The following files have been resolved:
...
[INFO] net.cakesolutions:scala-kafka-client_2.11:pom:0.10.0.0-RC2:compile
...
Try removing <type>pom</type> from the dependency declaration in your pom.xml.

"./sbt/sbt assembly" errors "Not a valid command: assembly" for Apache Spark project

I'm having trouble with installing Apache Spark on Ubuntu 13.04. Im using spark-0.8.1-incubating, and both ./sbt/sbt update and ./sbt/sbt compile work fine. However, when I do a ./sbt/sbt assembly I get the following error:
[info] Set current project to default-289e76 (in build file:/node-insights/server/lib/spark-0.8.1-incubating/sbt/)
[error] Not a valid command: assembly
[error] Not a valid project ID: assembly
[error] Not a valid configuration: assembly
[error] Not a valid key: assembly
[error] assembly
[error]
I googled for stuff related to this but couldn't find anything useful. Any guidance would be much appreciated.
The current project set to default-289e76 message suggests that sbt was called from outside of the Spark sources directory:
$ /tmp ./spark-0.8.1-incubating/sbt/sbt assembly
[info] Loading global plugins from /Users/joshrosen/.dotfiles/.sbt/plugins/project
[info] Loading global plugins from /Users/joshrosen/.dotfiles/.sbt/plugins
[info] Set current project to default-d0f036 (in build file:/private/tmp/)
[error] Not a valid command: assembly
[error] Not a valid project ID: assembly
[error] Not a valid configuration: assembly
[error] Not a valid key: assembly
[error] assembly
[error] ^
Running ./sbt/sbt assembly works fine from the spark-0.8.1-incubating directory (note the log output showing that the current project was set correctly):
$ spark-0.8.1-incubating sbt/sbt assembly
[info] Loading global plugins from /Users/joshrosen/.dotfiles/.sbt/plugins/project
[info] Loading global plugins from /Users/joshrosen/.dotfiles/.sbt/plugins
[info] Loading project definition from /private/tmp/spark-0.8.1-incubating/project/project
[info] Loading project definition from /private/tmp/spark-0.8.1-incubating/project
[info] Set current project to root (in build file:/private/tmp/spark-0.8.1-incubating/)
...
You typed "abt" twice, but shouldn't that be "sbt"? Apache Spark has its own copy of sbt, so make sure you're running Spark's version to pick up the "assembly" plugin among other customizations.
To run the Spark installation of sbt, go to the Spark directory and run ./sbt/sbt assembly .