Why does 2.11.1 fail with error: not found: type Application? - scala

I'm trying to compile the following code:
object Main extends Application{
println("Hello World");
}
But I'm getting this error:
/Users/xx/JavaProjects/ScalaApplication1/src/scalaapplication1/Main.scala:8: error: not found: type Application
object Main extends Application{
^
one error found
I'm using Scala 2.11.1.

Application has been deprecated from scala 2.9, probably it has been deleted in scala 2.11 (it still exists in scala 2.10) even though at the moment I can't find proofs for that, use App instead.
Proof found, this is the scala 2.11 branch on github which has only an App.scala and this is the 2.10 which has App.scala and Application.scala with a deprecated warning.

You need to extends the App trait, the Application trait doesn't exists.
How i've done compile:
object Main extends App{
println("Hello World");
}

Related

value should is not a member of String - Scala2.10

I want to cross compile my project across different Scala versions (2.10, 2.11, 2.12). I get this error message while compiling specs for 2.10 only. 2.11 and 2.12 work fine:
value should is not a member of String
Spec class looks as follows:
class ClassNameSpec extends WordSpec with Matchers {
// ...
}
I have also tried changing WordSpec to FlatSpec and still getting same error.
Using gradle - build.gradle has following related dependencies:
classpath 'gradle.plugin.com.github.maiflai:gradle-scalatest:0.19'
compile "org.scala-lang:scala-library:${scalaVersion}"
compile "org.scalactic:scalactic${scalaVersionSuffix}:3.0.5"
testRuntime 'org.pegdown:pegdown:1.4.2'
How can I make WordSpec or FlatSpec with Matchers work for Scala2.10? If not, what's the best work around?

Main extends scala.App is not working after upgraded to scala 2.11.0 to 2.12.0

I used the below code snippet (in scala-2.11.8) to make object as executable program. But when I migrated the scala version 2.12.0 it is not working. It is throwing error to implement some of the deprecated methods.
object Main extends App {
Console.println("Hello World ")
}
as there were a change in delayedInit method, How would I proceed to make my object as executable using App trait.
Q : How to make my object as executable in scala 2.12.0
Update : Facing this issue when Using Idea 14 with scala plugin
Working fine with scala REPL terminal
How are you running your snippet?
One behavior change is that it doesn't run as a script under 2.11 but does run under 2.12.
$ scala -nc ran.scala
Hello World
$ scala211 -nc ran.scala
$ cat ran.scala
object Main extends App {
Console.println("Hello World ")
}
Since that is the opposite of what you report, you're doing something totally different.

object scala in compiler mirror not found - running Scala compiler programatically [no sbt - no IDE] [duplicate]

I'm trying to run a Scala application packed as JAR (including dependencies) but this fails until the Scala library is added by using the -Xbootclasspath/p option.
Failing invocation:
java -jar /path/to/target/scala-2.10/application-assembly-1.0.jar
After the application did some of its intended output, the console shows:
Exception in thread "main"
scala.reflect.internal.MissingRequirementError: object scala.runtime
in compiler mirror not found.
at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:16)
at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:17)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:48)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:40)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:61)
at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:172)
at scala.reflect.internal.Mirrors$RootsBase.getRequiredPackage(Mirrors.scala:175)
at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackage$lzycompute(Definitions.scala:181)
at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackage(Definitions.scala:181)
at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackageClass$lzycompute(Definitions.scala:182)
at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackageClass(Definitions.scala:182)
at scala.reflect.internal.Definitions$DefinitionsClass.AnnotationDefaultAttr$lzycompute(Definitions.scala:1015)
at scala.reflect.internal.Definitions$DefinitionsClass.AnnotationDefaultAttr(Definitions.scala:1014)
at scala.reflect.internal.Definitions$DefinitionsClass.syntheticCoreClasses$lzycompute(Definitions.scala:1144)
at scala.reflect.internal.Definitions$DefinitionsClass.syntheticCoreClasses(Definitions.scala:1143)
at scala.reflect.internal.Definitions$DefinitionsClass.symbolsNotPresentInBytecode$lzycompute(Definitions.scala:1187)
at scala.reflect.internal.Definitions$DefinitionsClass.symbolsNotPresentInBytecode(Definitions.scala:1187)
at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1252)
at scala.tools.nsc.Global$Run.(Global.scala:1290)
at extract.ScalaExtractor$Compiler$2$.(ScalaExtractor.scala:24)
Working invocation:
java -Xbootclasspath/p:/path/to/home/.sbt/boot/scala-2.10.2/lib/scala-library.jar -jar /path/to/target/scala-2.10/application-assembly-1.0.jar
The strange thing about it is that the application-assembly-1.0.jar was built so that it includes all dependencies including the Scala library. When one extracts the JAR file it can be verified that the class files in the scala.runtime package have been included.
Creation of the JAR file
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.1") was added to project/plugins.sbt and the assembly target was invoked. A JAR file of about 25MB results.
Building the JAR with proguard shows the same runtime behavior as seen with assembly's JAR file.
Application code that triggers the MissingRequirementError
Some application code works fine and the previously described exception is triggered as soon as the new Run from the following fragment executes.
import scala.reflect.internal.util.BatchSourceFile
import scala.reflect.io.AbstractFile
import scala.reflect.io.Path.jfile2path
import scala.tools.nsc.Global
import scala.tools.nsc.Settings
…
import scala.tools.nsc._
object Compiler extends Global(new Settings()) {
new Run // This is line 24 from the stack trace!
def parse(path: File) = {
val code = AbstractFile.getFile(path)
val bfs = new BatchSourceFile(code, code.toCharArray)
val parser = new syntaxAnalyzer.UnitParser(new CompilationUnit(bfs))
parser.smartParse()
}
}
val ast = Compiler.parse(file)
Among others, scala-library, scala-compiler and scala-reflect are defined as dependencies in build.sbt.
For the curios / background information
The aim of the application is to aid in localization of Java and Scala programs. The task of the code fragment above is to get an AST from a Scala file in order to find method calls in there.
The questions
Given the Scala library is included in the JAR file, why is necessary to call the JAR using -Xbootclasspath/p:scala-library.jar?
Why do other parts of the application run just fine even though scala.runtime is reported as missing later?
The easy way to configure the settings with familiar keystrokes:
import scala.tools.nsc.Global
import scala.tools.nsc.Settings
def main(args: Array[String]) {
val s = new Settings
s processArgumentString "-usejavacp"
val g = new Global(s)
val r = new g.Run
}
That works for your scenario.
Even easier:
java -Dscala.usejavacp=true -jar ./scall.jar
Bonus info, I happened to come across the enabling commit message:
Went ahead and implemented classpaths as described in email to
scala-internals on the theory that at this point I must know what I'm
doing.
** PUBLIC SERVICE ANNOUNCEMENT **
If your code of whatever kind stopped working with this commit (most
likely the error is something like "object scala not found") you can
get it working again with either of:
passing -usejavacp on the command line
set system property "scala.usejavacp" to "true"
Either of these will alert scala that you want the java application
classpath to be utilized by scala as well.

Scalatest and scalamock - dependency trouble involving SuiteMixin

I'm trying to setup my project to use scalatest and scalamock.
I'm using scala version 2.10.0.
However, I cant seem to get the dependencies right.
I've started with this code:
class ControllerTest extends org.scalatest.FunSuite
with org.scalamock.scalatest.MockFactory {}
I've tried two combinations of versions:
1)
org.scalatest : scalatest_2.10 : 1.9.1
org.scalamock: scalamock-scalatest-support_2.10 : 3.0.1
This is what I get:
scala: bad symbolic reference.
A signature in MockFactory.class refers to type SuiteMixin in package org.scalatest which is not available.
It may be completely missing from the current classpath, or the version on the classpath might be incompatible with the version used when compiling MockFactory.class.
Note: in the scalamock documentation, the artifact id is specified without the trailing _2.10, but maven couldn't find any artifact named like this. Also, I couldn't find on their site what scalatest version should be used with scalamock.
2)
org.scalatest : scalatest_2.10 : 1.9.1
org.scalamock: scalamock-scalatest-support_2.10.0-RC5: 3.0-M8
The compiler says:
scala: overriding method nestedSuites in trait SuiteMixin of type => scala.collection.immutable.IndexedSeq[org.scalatest.Suite];
method nestedSuites in trait Suite of type => List[org.scalatest.Suite] has incompatible type
class ControllerTest extends FunSuite with MockFactory {
and
scala: class ControllerTest needs to be abstract, since:
it has 5 unimplemented members.
/** As seen from class ControllerTest, the missing signatures are as follows.
* For convenience, these are usable as stub implementations.
*/
def rerunner: Option[String] = ???
def run(testName: Option[String],args: org.scalatest.Args): org.scalatest.Status = ???
protected def runNestedSuites(args: org.scalatest.Args): org.scalatest.Status = ???
protected def runTest(testName: String,args: org.scalatest.Args): org.scalatest.Status = ???
protected def runTests(testName: Option[String],args: org.scalatest.Args): org.scalatest.Status = ???
So, what's up with this SuiteMixin trait?
If I use scalatest-support_2.10.0-RC5:3.0-M8, it appears to exist in scalatest lib.
If I use scalatest-support_2.10:3.0.1, it seems to have gone from said scalatest lib.
What kind of sorcery is this? And, more importantly, what version combination should I use to make it work?
Thanks!
If you have this dependency
"org.scalamock" %% "scalamock-scalatest-support" % "3.0.1" % "test"
It will automatically download the correct version of scalatest. In this case it's
org.scalatest#scalatest_2.10;2.0.M5b!scalatest_2.10.jar
In most cases where one library depends upon another you just add only that one library as dependency. Sbt-like tools will get the other dependencies.
EECOLOR's answer is correct. To elaborate, the cause of the problem was that the ScalaMock version you chose was compiled against a later version of ScalaTest (2.0.M5b) than the one you were explicitly trying to use (1.9.1).

Error in scala + dispatch

I am trying to GET a response from an API, using scala and dispatch. However, I get this error, after building. I googled for a solution, and tried cleaning, and resarting eclipse, but the error wont go away. What seems to be the problem? I use eclipse Helios (ie 3.6) and Scala v2.8.1, with Scala IDE v1.0.0.201104170033, installed from the Eclipse market.
dispatch{dispatch.type}.Http{object dispatch.Http} of type object dispatch.Http does not take parameters
This is my code.
class getList {
def main(args: Array[String]){
Http("http://foo.com/" >>> System.out)
}
}
What am I doing wrong?
What libraries have you downloaded? Are you sure the dependencies are set correctly? I tried with dispatch_http, version 8.0 for Scala 2.8.1, and it worked.
What imports are you using? I used these imports to make it work:
import dispatch.Http
import dispatch.HandlerVerbs._
Finally... class getList??? I assume this is a result of cut&pasting from actual code, but you should strive to produce a compilable example of your problem. Scala doesn't run programs from class, only from object, and it follows Java style of having classes start with an uppercase letter.
Here's the minimal code I used with SBT to get a working example.
Initializing:
~/test$ sbt
Project does not exist, create new project? (y/N/s) y
Name: test
Organization: test
Version [1.0]:
Scala version [2.7.7]: 2.8.1
sbt version [0.7.4]:
~/test$ cat project/build/TestProject.scala
import sbt._
class TestProject(info: ProjectInfo) extends DefaultProject(info) {
val dvers = "0.8.0"
val http = "net.databinder" %% "dispatch-http" % dvers
}
~/test$ cat src/main/scala/GetList.scala
import dispatch.Http
import dispatch.HandlerVerbs._
object GetList {
def main(args: Array[String]){
Http("http://foo.com/" >>> System.out)
}
}
~/test# sbt update run