I'm trying to run a Lift-2.4 web app following this tutorial http://scala-ide.org/docs/tutorials/lift24scalaide20/index.html
The problem is how to run this app (either on jetty, tomcat or other server)?!
I'm trying the command jetty-run, but I've got this error:
> jetty-run
[error] Not a valid command: jetty-run
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: jetty-run (similar: run)
[error] jetty-run
[error] ^
And when I do container:start, I've also got an error:
> container:start
[error] Not a valid key: start (similar: state, target, start-year)
[error] container:start
[error]
^
My configurations are:
The file "build.sbt" contains:
name := "lift-basic"
organization := "my.company"
version := "0.1-SNAPSHOT"
scalaVersion := "2.9.1"
EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource
libraryDependencies ++= {
val liftVersion = "2.4"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile",
"net.liftweb" %% "lift-mapper" % liftVersion % "compile",
"org.mortbay.jetty" % "jetty" % "6.1.26" % "test",
"junit" % "junit" % "4.7" % "test",
"ch.qos.logback" % "logback-classic" % "0.9.26",
"org.scala-tools.testing" %% "specs" % "1.6.9" % "test",
"com.h2database" % "h2" % "1.2.147"
)
}
And the file ".sbt/plugins/build.sbt" contains:
//Eclipse Plugin
resolvers += Classpaths.typesafeResolver
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0")
It sounds like you need to install the xsbt-web-plugin plugin for sbt.
Instructions are available here: https://github.com/JamesEarlDouglas/xsbt-web-plugin/wiki
That should provide you with container:start as well as jar packaging.
Related
I am wrestling with importing required jar files and deploying them into scala projects after writing build.sbt script. Resolvers deny downloading any scala libraries from neither sonar and maveen 2 resolvers. My scala version is 2.13.0 and sbt is 1.6.1
after compiling sbt builds the program yields errors stated below.
download error: Caught java.io.IOException (Server returned HTTP
response code: 400 for URL:
https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.0
/scala-library-2.13.0 .pom) while downloading
https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.0
/scala-library-2.13.0 .pom [error] download error: Caught
java.net.URISyntaxException (Illegal character in path at index 68:
http://download.java.net/maven/2/org/scala-lang/scala-library/2.13.0
/scala-library-2.13.0 .pom) while downloading
http://download.java.net/maven/2/org/scala-lang/scala-library/2.13.0
/scala-library-2.13.0 .pom [error] download error: Caught
java.net.ConnectException (Connection refused (Connection refused))
while downloading
http://repo.typesafe.com/typesafe/releases/org/scala-lang/scala-library/2.13.0
/scala-library-2.13.0 .po [error] Error downloading
org.json4s:json4s-native_2.13.0 :3.5.1
Here is my build.sbt script which means error does'nt stem from syntax error.
lazy val commonSettings = Seq(
organization := "scala_REINFORCEMENTLEARNING",
organizationName:="trial",
scalaVersion := "2.13.0",
version := "0.1.0-SNAPSHOT"
)
lazy val root = (project in file("."))
.settings(
commonSettings,
name := "sarsamora",
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.10" % "test",
"com.typesafe" % "config" % "1.2.1",
"commons-io" % "commons-io" % "2.4",
"jline" % "jline" % "2.12.1",
"org.json4s" %% "json4s-native" % "3.5.1",
// logging
"ch.qos.logback" % "logback-classic" % "1.1.7",
"com.typesafe.scala-logging" %% "scala-logging" % "3.4.0",
"org.scala-graph" %% "graph-core" % "1.11.3",
"org.scalanlp" %% "breeze" % "0.13",
"org.scalanlp" %% "breeze-natives" % "1.1",
"org.scalanlp" %% "breeze-viz" % "1.1",
"org.jfree" % "jfreechart" % "1.0.19"
)
)
lazy val compiler = (project in file(".")).dependsOn(root)
.settings(commonSettings:_*)
resolvers ++= Seq(
("Typesafe" at "http://repo.typesafe.com/typesafe/releases/").withAllowInsecureProtocol(true),
("Java.net Maven2 Repository" at "http://download.java.net/maven/2/").withAllowInsecureProtocol(true),
)
Look's like you've got an extra whitespace in your version number:
https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.0/scala-library-2.13.0 .pom
Fix the Scala version in your build.sbt and it should be it.
I have a scala spark project that fails because of some dependency hell. Here is my build.sbt:
scalaVersion := "2.13.3"
val SPARK_VERSION = "3.2.0"
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.3.1",
"com.github.pathikrit" %% "better-files" % "3.9.1",
"org.apache.commons" % "commons-compress" % "1.14",
"commons-io" % "commons-io" % "2.6",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",
"ch.qos.logback" % "logback-classic" % "1.2.3" exclude ("org.slf4j", "*"),
"org.plotly-scala" %% "plotly-render" % "0.8.1",
"org.apache.spark" %% "spark-sql" % SPARK_VERSION,
"org.apache.spark" %% "spark-mllib" % SPARK_VERSION,
// Test dependencies
"org.scalatest" %% "scalatest" % "3.2.10" % Test,
"com.amazon.deequ" % "deequ" % "2.0.0-spark-3.1" % Test,
"org.awaitility" % "awaitility" % "3.0.0" % Test,
"org.apache.spark" %% "spark-core" % SPARK_VERSION % Test,
"org.apache.spark" %% "spark-sql" % SPARK_VERSION % Test
Here is the build failure:
[error] stack trace is suppressed; run 'last update' for the full output
[error] stack trace is suppressed; run 'last ssExtractDependencies' for the full output
[error] (update) lmcoursier.internal.shaded.coursier.error.FetchError$DownloadingArtifacts: Error fetching artifacts:
[error] https://repo1.maven.org/maven2/org/apache/avro/avro-mapred/1.10.2/avro-mapred-1.10.2-hadoop2.jar: not found: https://repo1.maven.org/maven2/org/apache/avro/avro-mapred/1.10.2/avro-mapred-1.10.2-hadoop2.jar
[error] (ssExtractDependencies) lmcoursier.internal.shaded.coursier.error.FetchError$DownloadingArtifacts: Error fetching artifacts:
[error] https://repo1.maven.org/maven2/org/apache/avro/avro-mapred/1.10.2/avro-mapred-1.10.2-hadoop2.jar: not found: https://repo1.maven.org/maven2/org/apache/avro/avro-mapred/1.10.2/avro-mapred-1.10.2-hadoop2.jar
[error] Total time: 5 s, completed Dec 19, 2021, 5:14:33 PM
[info] shutting down sbt server
Is this caused by the fact that I',m using Scala 2.13?
I had to do the inevitable and add this to my build.sbt:
ThisBuild / useCoursier := false
I'm using Fedora Linux and sbt. I think I've tried everything, but I can't persuade sbt to use Scala 2.12.2 to compile my project.
When I compile the same project with:
Gradle,
IntelliJ IDEA,
SBT on a different Linux distro,
everything works. I just can't get it to work on Fedora Linux and sbt.
Here's my build.sbt:
scalaVersion := "2.12.2"
scalaVersion in ThisBuild := "2.12.2"
crossScalaVersions := Seq(scalaVersion.value)
scalacOptions := Seq("-unchecked", "-deprecation", "-feature", "-language:postfixOps")
libraryDependencies ++= Seq("org.xerial" % "sqlite-jdbc" % "3.18.0",
"org.apache.httpcomponents" % "httpclient" % "4.5.3",
"commons-codec" % "commons-codec" % "1.10",
"commons-cli" % "commons-cli" % "1.4",
"org.hjson" % "hjson" % "1.0.0",
"log4j" % "log4j" % "1.2.17",
"org.zeromq" % "jeromq" % "0.4.0",
"com.nimbusds" % "nimbus-jose-jwt" % "4.23",
"ws.wamp.jawampa" % "jawampa-core" % "0.5.0",
"ws.wamp.jawampa" % "jawampa-netty" % "0.5.0",
"org.glassfish.tyrus" % "tyrus-websocket-core" % "1.2.1",
"org.glassfish.tyrus.bundles" % "tyrus-standalone-client" % "1.13.1",
"org.scalactic" %% "scalactic" % "3.0.1",
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
"org.postgresql" % "postgresql" % "42.1.1")
// https://mvnrepository.com/artifact/org.apache.commons/commons-compress
libraryDependencies += "org.apache.commons" % "commons-compress" % "1.14"
// https://mvnrepository.com/artifact/org.tukaani/xz
libraryDependencies += "org.tukaani" % "xz" % "1.6"
// https://mvnrepository.com/artifact/net.sourceforge.htmlunit/htmlunit
libraryDependencies += "net.sourceforge.htmlunit" % "htmlunit" % "2.27"
Here's my project/build.properties:
sbt.version=0.13.15
scala.version=2.12.2
build.scala.version=2.12.2
def.scala.versions=2.12.2
Every time I start sbt and try to compile, I'm getting some syntax errors (I've changed some strings to xxx, sorry):
[info] Compiling 76 Scala sources to /home/antek/dev/scala/xxx/target/scala-2.12/classes...
[error] /home/antek/dev/scala/xxx/src/main/scala/api/xxx.scala:168: macros cannot be partially applied
[error] httpPost(transApi, args + ("xxx" → f"$currentTime%d"), "API-Key", "API-Hash")
[error] ^
[error] /home/antek/dev/scala/xxx/src/main/scala/api/xxx.scala:39: macros cannot be partially applied
[error] httpPost(transApi, args + ("xxx" → f"$currentTime%d"), "API-Key", "API-Hash")
[error] ^
[error] /home/antek/dev/scala/xxx/src/main/scala/api/HttpSignOperation.scala:51: macros cannot be partially applied
[error] Log.put(f"HTTP GET returned status $status%d")
[error] ^
[error] /home/antek/dev/scala/xxx/src/main/scala/api/HttpSignOperation.scala:82: macros cannot be partially applied
[error] Log.put(f"HTTP POST returned status $status%d")
[error] ^
[error] /home/antek/dev/scala/xxx/src/main/scala/api/JWSOperation.scala:38: macros cannot be partially applied
[error] Log.put(f"HTTP POST returned status $status%d")
[error] ^
[error]
[error] while compiling: /home/antek/dev/scala/xxx/src/main/scala/api/Order.scala
[error] during phase: typer
[error] library version: version 2.10.4
[error] compiler version: version 2.10.4
[error] reconstructed args: -classpath /home/antek/dev/scala/xxx/target/scala-2.12/classes:/home/antek/.ivy2/cache/org.xer[... cut ...]64/jre/classes:/home/antek/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.2.jar
I have written the following sbt file
name := "Test"
version := "1.0"
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-client" % "2.7.1",
"org.apache.spark" % "spark-core_2.10" % "1.3.0",
"org.apache.avro" % "avro" % "1.7.7",
"org.apache.avro" % "avro-mapred" % "1.7.7"
)
mainClass := Some("com.test.Foo")
I also have the following assembly.sbt file in projects folder
resolvers += Resolver.url("bintray-sbt-plugins", url("http://dl.bintray.com/sbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.0")
when i do sbt assembly i get a huge list of errors
[error] (*:assembly) deduplicate: different file contents found in the following:
[error] /Users/abhishek.srivastava/.ivy2/cache/com.esotericsoftware.kryo/kryo/bundles/kryo-2.21.jar:com/esotericsoftware/minlog/Log$Logger.class
[error] /Users/abhishek.srivastava/.ivy2/cache/com.esotericsoftware.minlog/minlog/jars/minlog-1.2.jar:com/esotericsoftware/minlog/Log$Logger.class
[error] deduplicate: different file contents found in the following:
[error] /Users/abhishek.srivastava/.ivy2/cache/com.esotericsoftware.kryo/kryo/bundles/kryo-2.21.jar:com/esotericsoftware/minlog/Log.class
[error] /Users/abhishek.srivastava/.ivy2/cache/com.esotericsoftware.minlog/minlog/jars/minlog-1.2.jar:com/esotericsoftware/minlog/Log.class
[error] deduplicate: different file contents found in the following:
I was able to resolve the problem. actually there is no need to build a fat jar because the "spark-submit" tool will have everything in the classpath anyway.
thus the right way to build the jar file is
name := "Test"
version := "1.0"
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-client" % "2.7.1" % "provided",
"org.apache.spark" % "spark-core_2.10" % "1.3.0" % "provided",
"org.apache.avro" % "avro" % "1.7.7" % "provided",
"org.apache.avro" % "avro-mapred" % "1.7.7" % "provided"
)
mainClass := Some("com.test.Foo")
1. use the MergeStrategy, see sbt-assembly
2. exclude the duplicated jars, such as:
lazy val hbaseLibSeq = Seq(
("org.apache.hbase" % "hbase" % hbaseVersion).
excludeAll(
ExclusionRule(organization = "org.slf4j"),
ExclusionRule(organization = "org.mortbay.jetty"),
ExclusionRule(organization = "javax.servlet")),
("net.java.dev.jets3t" % "jets3t" % "0.6.1" % "provided").
excludeAll(ExclusionRule(organization = "javax.servlet"))
)
3. use the provided scope
show dependency tree:
➜ cat ~/.sbt/0.13/plugins/plugins.sbt
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.5")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
➜ cat ~/.sbt/0.13/global.sbt
net.virtualvoid.sbt.graph.Plugin.graphSettings
➜ sbt dependency-graph
Suddenly as of today my project has stopped compiling successfuly. Upon further investigation I've found out the reason is play-json library that I include in dependencies.
Here's my build.sbt:
name := """project-name"""
version := "1.0"
scalaVersion := "2.10.2"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.2.1",
"com.typesafe.akka" %% "akka-testkit" % "2.2.1",
"org.scalatest" %% "scalatest" % "1.9.1" % "test",
"org.bouncycastle" % "bcprov-jdk16" % "1.46",
"com.sun.mail" % "javax.mail" % "1.5.1",
"com.typesafe.slick" %% "slick" % "2.0.1",
"org.postgresql" % "postgresql" % "9.3-1101-jdbc41",
"org.slf4j" % "slf4j-nop" % "1.6.4",
"com.drewnoakes" % "metadata-extractor" % "2.6.2",
"com.typesafe.play" %% "play-json" % "2.2.2"
)
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
If I try to create a new project in activator with all the lines except "com.typesafe.play" %% "play-json" % "2.2.2" then it compiles successfully. But once I add play-json I get the folloing error:
[error] References to undefined settings:
[error]
[error] *:playCommonClassloader from echo:run
[error]
[error] docs:managedClasspath from echo:run
[error]
[error] *:playReloaderClassloader from echo:run
[error]
[error] echo:playVersion from echo:echoTracePlayVersion
[error]
[error] *:playRunHooks from echo:playRunHooks
[error] Did you mean echo:playRunHooks ?
[error]
And I keep getting this error even if I remove play-json line. Why is it so? What should I do to fix it?