Getting started with Lift and Lifty - scala

I am trying to get started with the Lift framework, reading Lift in Action. I would like to follow along with the examples, but I immediately stumble into a problem with installing Lift. I know that there are various ways to get started easily with Lift, but I would like to use Lifty, as the book does, to be able to follow it.
The problem is that both Lifty and sbt (and Lift too!) have moved forward since the book was published. I installed sbt from the Typesafe repository for Ubuntu. Now I am stuck trying to install Lifty.
Following Lifty documentation and this answer on SO - due to the fact that Lifty has not released a binary for sbt 0.11.3 - I figured I should put the following in ~/.sbt/plugins/build.sbt:
resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
addSbtPlugin("org.lifty" % "lifty" % "1.7.4")
libraryDependencies +=
Defaults.sbtPluginExtra(
"org.lifty" % "lifty" % "1.7.4",
"0.11.2",
"2.9.1"
)
The latter is to tell sbt to use the Lifty plugin for sbt 0.11.2.
Now sbt seems to be able to download Lifty and starts correctly, but I do not have a lifty command. So when I do
lifty learn lift https://raw.github.com/Lifty/lifty/master/lifty-recipe/lifty.json
sbt complains:
[error] Not a valid key: lifty (similar: history)
[error] lifty learn lift https://raw.github.com/Lifty/lifty/master/lifty-recipe/lifty.json
[error] ^
How should I install Lifty? Please note that I am new to Scala, sbt and Lift.
EDIT
I managed to install Lifty by downgrading to sbt 0.7.7. But then if I do
> lift create project-blank
> reload
> update
I get the error
[error] sbt.ResolveException: unresolved dependency: net.liftweb#lift-webkit_2.9.1;2.3-RC3: not found
[error] unresolved dependency: org.scala-tools.testing#specs_2.9.1;1.6.6: not found
[info] == update ==
[error] Error running update: sbt.ResolveException: unresolved dependency: net.liftweb#lift-webkit_2.9.1;2.3-RC3: not found
[error] unresolved dependency: org.scala-tools.testing#specs_2.9.1;1.6.6: not found

I hate to break it to you, but lifty is gone. As of this writing, sbt's stable is 0.13.0. Looking at sbt community repo, the only version that was released was 1.7.4 for sbt 0.11.2.
The official website says:
The Lift Cookbook is the most up-to-date resource to learn how to use Lift.
There's a section named Creating a Lift Project from Scratch Using SBT:
Problem
You want want to create a Lift web project from scratch without using the ZIP files provided on the official Lift website.
Solution
You will need to configure SBT and the Lift project yourself. Luckily, only five small files are needed.
First, create an SBT plugin file at project/plugins.sbt (all filenames are given relative to the project root directory):
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "0.3.0")
This file tells SBT that you will be using the xsbt-web-plugin.
Next, create an SBT build file, build.sbt...
Unfortunately xsbt-web-plugin 0.3.0 is for sbt 0.12. So you have to either use sbt 0.12, or modify the instruction a bit. The latest xsbt-web-plugin for sbt 0.13 is 0.4.2, so in project/plugins.sbt put:
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "0.4.2")
resolvers += Resolver.sonatypeRepo("public")
I was able to follow along with the rest of instructions on the page...
Eventually I got everything pulled in by sbt 0.13, and was able to start the container:
> container:start
[info] Compiling 1 Scala source to /foo/sbt-lift-test/target/scala-2.10/classes...
[info] jetty-8.1.7.v20120910
....
[success] Total time: 2 s, completed Sep 20, 2013 10:34:22 PM
Open http://localhost:8080/ using the browser:
Welcome, you now have a working Lift installation

Related

How to create executable jar in scala which can run on jvm?

I am using scala version 2.11.4, I have tried various options like sbt-assembly, build artifact (Intellij Idea feature), sbt package. Unfortunately, none of them worked form me.
I attempted following things :
With sbt-assembly :
Created assembly.sbt file and added following line :
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0")
build.sbt :
scalaVersion in ThisBuild := "2.11.4"
resolvers += Resolver.url("bintray-sbt-plugins", url("http://dl.bintray.com/sbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)
ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
I got the following error
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.eed3si9n:sbt-assembly:0.12.0 (sbtVersion=0.13, scalaVersion=2.11)
With 'build artifact' feature using Intellij Idea 15
Able to create a jar. However, not able to execute it. Was getting following error:
Invalid or corrupt jarfile
For this I tried the command : java -jar JAR_FILE
With sbt package :
Able to create JAR. However, not able to execute it. Was getting following error :
java.lang.NoClassDefFoundError scala/Function0
I was trying with the command :
java -cp scala-library.jar -jar JAR_FILE
Resolved
I am able to create jar by switching to scala version 2.10.5 and then used sbt-assembly plugin. Slightly disappointed with the fact that there is no available solution to create executable jar with latest version of scala.
If you are using sbt-assembly plugin, the correct task to perform is called assembly. When using IntelliJ IDEA, sbt assembly needs to be performed from a command line, the IDE is still unable to perform such SBT tasks.
The resulting jar, which includes all dependencies, is usually called a fat jar - if you need some more searching, this is what to search for.
Since I can't comment yet, I'll use answer, but more of a question - I have been using sbt package extensively for exactly this. I cd into the directory that holds src/main/scala|java and running sbt package, and then pushing jar/war file to the desired destination, in my case jetty.
Can you explain exactly what you're doing, the output and details on the issue?

deploy scalatra app on heroku error plugin not found

I followed the guide of deploying a Scalatra app on Heroku [lien] http://www.scalatra.org/guides/deployment/heroku.html#toc_177 and I get the following error:
> [error] (*:update) sbt.ResolveException: unresolved dependency: >com.typesafe.startscript#xsbt-start-script-plugin;0.5.3: not found
My version of SBT is 0.13.0..
For information I'm debutante with scalatra and sbt,Please can you help me..
As you already mentioned your sbt version is 0.13.0 so:
on https://github.com/sbt/sbt-start-script
there are instructions for 0.13.0 version. So we need to:
Use
com.typesafe.sbt.SbtStartScript.startScriptForClassesSettings: _* instead of com.typesafe.startscript.StartScriptPlugin.startScriptForClassesSettings: _* in build.scala and
In project/plugins.sbt we need to add start script plugin like addSbtPlugin("com.typesafe.sbt" % "sbt-start-script" % "0.10.0") instead of ddSbtPlugin("com.typesafe.startscript" % "xsbt-start-script-plugin" % "0.5.3")
And as a bonus: don’t forget to change servlet name in src/main/scala/JettyLauncher.scala to one you have e.g. com.blog.BlogServlet instead of one in tutorial com.example.app.MyScalatraServlet

sbt: cobertura4sbt cannot be found from sbt 0.12

I am about to use cobertura4sbt sbt plugin from maven repository.
I added the following lines to project\plugins.sbt:
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/groups/scala-tools"
addSbtPlugin("de.johoop" % "cobertura4sbt" % "1.0.0")
However, as I tried to "sbt compile", it always appended my local SBT and Scala version number to the resolving path so that the corresponding pom cannot be found. Do I miss something anywhere?
[warn] ==== Sonatype OSS Snapshots: tried
[warn] https://oss.sonatype.org/content/groups/scala-tools/de/johoop/cobertura4sbt_2.9.2_0.12/1.0.0/cobertura4sbt-1.0.0.pom
[warn] ==== public: tried
cobertura4sbt on sbt 0.7.4
The auto-postfixing of Scala and sbt version was added a while back in sbt to distinguish plugins for different releases of sbt. From this source, cobertura4sbt looks like it was built for 0.7.4, but the author says the plugin is no longer maintained:
This SBT plug-in enables you to measure your code coverage with the help of the great Cobertura tool.
However, since Cobertura is not really actively developed any more, I decided to stop working on this plugin for the time being, and instead started jacoco4sbt. Please ponder using jacoco4sbt instead of this plugin...
jacoco4sbt seems to be available for the latest sbt 0.13.0 too. Either plugin you choose, follow the instruction in the wiki.
jacoco4sbt on sbt 0.12.x
Given the log, I am assuming you're using sbt 0.12.x. jacoco4sbt for sbt 0.12 is published at Sonatype OSS, and the latest seems to be 2.0.0: https://oss.sonatype.org/content/groups/public/de/johoop/jacoco4sbt_2.9.2_0.12/2.0.0/
Try putting this in project/plugins.sbt:
resolvers += Resolver.sonatypeRepo("public")
addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.0.0")
and in jacoco.sbt:
jacoco.settings
This loads jacoco:cover task into sbt shell, which I was able to run and get the report out in target/scala-2.10/jacoco directory.

Lifty and SBT 0.12

I'm new to using SBT, and I'm trying to install and configure Lifty, however when I try to run sbt, I get the following error:
[error] (*:update) sbt.ResolveException: unresolved dependency: org.lifty#lifty;1.7.4: not found
As per the Installing the Plugin instructions for Lifty, my ~/.sbt/plugins/build.sbt file looks like:
resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
addSbtPlugin("org.lifty" % "lifty" % "1.7.4")
And my ~/.sbt/build.sbt file includes the line:
seq( Lifty.liftySettings : _*)
However, when trying to run this, I get the SBT error listed above, and I get a similar error if I try to use the 1.7.5-SNAPSHOT version of Lifty instead.
I'm using SBT launcher version 0.12.0 and Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_17) on Ubuntu 12.10.
Thank you!
You are using the wrong definition. Here is what you need;
resolvers += Resolver.url("sbt-plugin-snapshots", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-snapshots/"))(Resolver.ivyStylePatterns)
addSbtPlugin("org.lifty" % "lifty" % "1.7.4")
If you want to make this available for all projects, then put in ~/.sbt/plugins/plugins.sbt. Otherwise it goes in: ProjectFolder/project/plugins.sbt
But they don't have a Scala 2.10 or SBT 0.12 release out.. Look HERE for what is available.

Installing sbteclipse

i have problems top use sbteclipse
What I have done:
went to my global sbt folder.
created a plugins folder
created the file plugins.sbt with addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
went to my eclipse project and created a build.sbt file
it contains:
name := "foo"
version := "1.0"
scalaVersion := "2.9.2"
libraryDependencies += "net.java.dev.jna" % "jna" % "3.4.0"
I am selecting the project folder in my cmd. and type sbt eclipse
But I always get the following error
[error] Not a valid command: eclipse (similar: help, alias)
[error] Not a valid project ID: eclipse
[error] Expected ':'
[error] Not a valid key: eclipse (similar: deliver, licenses, clean)
[error] eclipse
[error] ^
ps: I am using Windows. I am also using sbt 0.12
Your global sbt folder is at %USERPROFILE%\.sbt (C:\Users\<username>\.sbt most likely). So your plugins should be defined at %USERPROFILE%\.sbt\plugins\plugins.sbt
Failing this you can add it to your project directly. Add the file path is <project_root>\project\plugins.sbt. If the project directory doesn't exist you will need to create it.
I think that I might have found a solution. First, the default directory checked for plugins configuration is 'USER_HOME/.sbt/plugins' and NOT 'USER_HOME/.sbt/0.13/plugins'.
Secondly, the sbt version specified seems to matter. In 'PROJECT_HOME/project/build.properties', there's an 'sbt.version' property. If the version of sbt specified in this file is different from the actually installed version of sbt, there's likely to be an issue. I think I was affected more so by this because I'm using an Activator template and it already had 'sbt.version' specified in this 'build.properties' file.
While nosing around, I came across this
"Support for plugin configuration in project/plugins/ has been removed. It was deprecated since 0.11.2" from sbt website at http://www.scala-sbt.org/0.13.0/docs/Community/ChangeSummary_0.13.0.html. I still see a lot of guys pointing that it should be configured in 'PROJECT_HOME/projects/plugins.sbt'. I think this is very confusing.
I had similar a issue and answered to a similar question.
I tried "everything" and, eventually, I just had to update my sbt from 0.13.1 to 0.13.9.