Lift-2.5 build issue in sbt/Eclipse - eclipse

I'm trying to get a mac development environment operational around Eclipse, SBT and Lift. Once installed as near to proper as I'm able to manage, I can run the app from sbt, but Eclipse still reports problems.
Eclipse is the Scala IDE build of Eclipse SDK, Build id:
3.0.1-vfinal-20130711-0941-Typesafe.
SBT is macport installed: sbt #0.12.3_1
Lift is the most recent 2.5 zip (This from this page.)
This tutorial was used for initial guidance. However, this tutorial is for a somewhat earlier version of Lift and associated dependencies, including the sbt-eclipse plugin. What I landed at was the 2.2 version of the eclipse plugin, and in my ~/.sbt/plugin/build.sbt I have this single line:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.2.0")
Per the tutorial instructions, I'm pulling over the source file (of Lift's lift_basic project specifically) and modifying my project build.sbt to the following:
name := "sample project"
organization := "com.nford"
version := "0.1-SNAPSHOT"
scalaVersion := "2.10.1"
EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource
libraryDependencies ++= {
val liftVersion = "2.5"
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"
)
}
Importing the project into Eclipse works fine, except for 20 errors, mostly around the test cases. These include, but are not limited to:
object eclipse is not a member of package org
not found: value JQueryModule
Googling errors like this I see a lot of stuff from a year ago, largely which seems to be a package mismatch. From this research I was able to make some changes (reflected in the build.sbt, etc. above):
Upgrade scala version to 2.10.1
Upgrade lift version to 2.5
Use sbt-eclipse 2.2 plugin
Yet I'm still receiving these errors. To verify; I have updated, from the sbt terminal console, and run the eclipse build from there as well. I imported the project to Eclipse after that point. I am unable to determine where the package mismatches are coming from (or indeed why they can't be discovered, since they exist on the system and sbt can find them). Is this an eclipse IDE plugin weakness, or a solvable problem? Or, in my obvious newness to Scala Lift, am I missing something really obvious?

JQueryModule is not part of Lift. You need to add:
"net.liftmodules" %% "lift-jquery-module_2.5" % "2.3"
Jetty:
"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container,compile",
"org.eclipse.jetty" % "jetty-servlets" % "8.1.7.v20120910" % "container,compile",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container,compile" artifacts Artifact("javax.servlet", "jar", "jar")
Specs2:
"org.specs2" %% "specs2" % "1.14"

Related

lift libs in Eclipse ScalaIDE is incompatible with all scala versions

Last day i start Scala with lift framework and Eclipse IDE. after checking this link:
http://scala-ide.org/docs/tutorials/lift24scalaide20/
I setup my project with eclipse. the first time the lift-basic runs as well as any project. but after trying to start a new project eclipse got 12 errors to me with content like this:
lift-actor_2.12-3.0.1.jar of lift_parsing_web build path is cross-compiled with an incompatible version of Scala (2.12.0). In case this report is mistaken, this check can be disabled in the compiler preference page.
hear is my build.sbt file:
name := "lift-parsing"
organization := "my.company"
version := "0.1-SNAPSHOT"
scalaVersion := "2.12.1"
libraryDependencies ++= {
val liftVersion = "3.0.1"
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_2.9.1" % "1.6.9",
"com.h2database" % "h2" % "1.2.147"
)
}
in this file i test lift 3.0.1 with scala 2.12.1 as this two version are installed.
but before this test I used the default 2.9.1 scala version and 2.4 lift version and also same problems. in some solutions i change the compiler setting and ignore this error but after that eclipse can't biuld the project and make .class file.
scala: 2.12.1
sbt: 0.13
lift: 3.0.1
finally this is my screen error. thanks for help
errors screenshot
I would check to see if Eclipse has a separate Scala version configuration beyond the one that you define in your sbt file. 2.12.0 and 2.12.1 should be binary compatible, so this shouldn't be a problem if you're using 2.12.1. Also try to build this directly using sbt and see if it registers a problem---if not, that implies it's probably an Eclipse configuration issue.

Configuring Lift with xsbt-web-plugin: finding the main method class

I'm attempting to create 'from scratch' a Lift web application and running into some difficulty. I started with xsbt-web-plugin version 2.1, and managed to get it working with a simple Jetty servlet. Then I tried to integrate information from the Lift Cookbook.
This is my build.sbt:
organization := "ford.nathaniel"
name := "Lift From Scratch"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.7"
libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided"
enablePlugins(JettyPlugin)
libraryDependencies ++= {
val liftVersion = "3.0-M8"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile",
"org.eclipse.jetty" % "jetty-webapp" % "9.2.1.v20140609" % "container, test",
"org.eclipse.jetty" % "jetty-plus" % "9.2.1.v20140609" % "container, compile"
)
}
I have a (one line) project/plugins.sbt:
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "2.1.0")
I lifted the Boot.scala file directly from the above-linked Cookbook and placed it in src/main/scala/bootstrap, and similarly src/main/webapp/WEB-INF/web.xml. I can run sbt from the command line, and it loads cleanly, but when I try container:start...
> container:start
[info] starting server ...
[success] Total time: 0 s, completed Mar 3, 2016 9:52:25 PM
Error: Could not find or load main class
>
I am unclear on how sbt is meant to find Lift's main class. I looked through a lot of older versions of sbt configuration, which differ because earlier versions use earlier versions of the xsbt plugin. (Specifically, you see things like seq(webSettings :_*) - what does that even do?) I pulled recent versions of jetty-webapp and jetty-plus, so I don't think that's the problem. On the other hand, none of those configurations make clear how Lift figures out where Boot.scala is, and in turn I'm not sure how to write the configuration such that it knows how to bootstrap the framework.
One main difference between the two sources is that the new Jetty README configures the servlet like this:
libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided"
enablePlugins(JettyPlugin)
containerLibs in Jetty := Seq("org.eclipse.jetty" % "jetty-runner" % "9.2.1.v20140609" intransitive())
containerMain in Jetty := "org.eclipse.jetty.runner.Runner"
This seems to configure a SettingKey on the Jetty plugin, and point to the Jetty runner to kick off the servlet. However, given that I'm not running through a standard servlet, but through a filter configured to point to the Lift app in web.xml, this seemed like something I should remove.
Clearly I'm misunderstanding something. How do I diagnose why the xsbt-web-plugin is not picking up the Lift framework? It seems like either there is configuration-by-convention I can't find or I need to do something special with Jetty to point to the web.xml filter. Can anyone help clarify how to diagnose this, or elucidate how the two libraries should work together?
The following build.sbt ended up working for me when executed as jetty:start (rather than container:start). It appears that net.liftweb needs to be included as a libraryDependency rather than in the containerLibs, and that the Jetty plugin manages the container. I don't understand particularly, though, what the difference is or how to diagnose this in the future (ended up just trying a lot of different things).
Notably, though, the Boot.scala class of Lift is picked up automagically if the web.xml file is set up to use a Lift filter.
organization := "ford.nathaniel"
name := "Lift From Scratch"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.7"
libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided"
//logLevel := Level.Debug
enablePlugins(JettyPlugin)
libraryDependencies ++= {
val liftVersion = "3.0-M8"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile"
)
}
containerLibs in Jetty := {
val liftVersion = "3.0-M8"
Seq(
"org.eclipse.jetty" % "jetty-webapp" % "9.2.1.v20140609",
"org.eclipse.jetty" % "jetty-plus" % "9.2.1.v20140609",
"org.eclipse.jetty" % "jetty-runner" % "9.2.1.v20140609" intransitive()
)
}
containerMain in Jetty := "org.eclipse.jetty.runner.Runner"

SBT 0.7.7 incremental recompilation doesnt work anymore

I'm using sbt 0.7.7 on ubuntu 12.10 to build a Lift app (Lift 2.4/Java 1.6/ Scala 2.7.7)
When I modify a source file, the sbt compiler recompiles all (even independent) files.
A debug output of "compile" shows:
[debug] External /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/jce.jar not on classpath.
[debug] External dependency /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/jce.jar not found.
I'm using ~compile and the file is available in the correct path.
Can anybody help me?
** Solution **
Thanks for your help.
It looks like sbt 0.7.7 can't handle symlinks correctly.
I removed the symlink and replaced it by a copy of the original file. This solved the problem.
But we're also updating to sbt 12.3 as soon as possible.
I have this file on my ubuntu 13.04
are you sure they're independent? Is it checkable in some way?
what command do you use for compilation? ~ compile ?
I'd suggest to move from the old SBT, old Lift and old Scala anyway. They're far-far away old, new versions have many improvements in performance and allowed techniques. And in the Scala environment it's common to evolutionize quickly, reducing the maintenance period. Check out the most recent official template: https://github.com/lift/lift_25_sbt/
SBT 0.7.7 is severely deprecated. Unless there is any specific reason for which you have to use that version, a 0.12.3 upgrade will make things much easier.
Most frameworks do not legacy support that version of SBT.
Make sure Java is there
Don't use the open source version of the JDK, it is known to cause hassle with Scala at times.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
Sample config
name := "YourApp"
version := "0.1-SNAPSHOT"
scalaVersion := "2.10.0"
seq(com.github.siasia.WebPlugin.webSettings :_*)
seq(jrebelSettings: _*)
jrebel.webLinks <++= webappResources in Compile
resolvers ++= Seq(
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases"
)
libraryDependencies ++= {
val liftVersion = "2.5-RC6"
Seq(
"commons-lang" % "commons-lang" % "2.6",
"net.liftweb" %% "lift-webkit" % liftVersion % "compile",
"net.liftweb" %% "lift-mongodb-record" % liftVersion % "compile",
"org.mongodb" %% "casbah" % "2.5.0" % "compile",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container,compile",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container,compile" artifacts Artifact("javax.servlet", "jar", "jar"),
"org.specs2" %% "specs2" % "1.12.3" % "test",
"ch.qos.logback" % "logback-classic" % "1.0.7" % "compile"
)
}
classpathTypes ~= (_ + "orbit")
port in container.Configuration := 9100
EclipseKeys.withSource := true

Adding a third-party library to Scala project (Idea 12 with SBT plugin)

I'm developing a Scala application in IntelliJ Idea 12. I have sbt plugin for Idea installed (Setting -> Plugins -> Browse repositories ...). Now I want to use some extra libraries for Scala, let's say one of them is https://github.com/stevej/scala-json. So I downloaded zip file from its source code from its github repository.
What do I do next? What is the standard way of adding a third-party library to Scala project using Intelli Idea 12 with SBT plugin installed?
Try something like this in the .sbt file:
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "1.0.0",
"postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"org.scalatest" %% "scalatest" % "1.9.1",
"net.sf.opencsv" % "opencsv" % "2.3",
"org.apache.commons" % "commons-math3" % "3.0"
)
you have to create your .sbt file in your project directory if you don't have one.
This is a quick tutorial on sbt (and another one)

What do the % and %% operators do when setting up SBT dependencies?

In Lift Web Framework, dependencies for Simple Build Tool (SBT) are specified in LiftProject.scala. That file includes this code:
override def libraryDependencies = Set(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile->default",
"net.liftweb" %% "lift-mapper" % liftVersion % "compile->default",
"org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default",
"junit" % "junit" % "4.5" % "test->default",
"org.scala-tools.testing" %% "specs" % "1.6.6" % "test->default",
"org.scala-lang" % "scala-compiler" % "2.8.1" % "test->default",
"org.apache.tomcat" % "tomcat-juli" % "7.0.0" % "test->default",
"com.h2database" % "h2" % "1.2.138"
) ++ super.libraryDependencies
What do the % and %% operators do here? If I paste this code into the scala interpreter, it errors out, and neither % nor %% is defined for String or RichString. What's going on here?
The difference between these functions is that %% considers Scala version when SBT resolve dependency, so for example net/liftweb/lift-webkit_2.8.1/2.3/lift-webkit_2.8.1-2.3.jar will be downloaded from repo.
Regarding compile error - these methods should be called when some implicit methods defined in SBT class hierarchy that make actual conversion are in scope.
Best regards,
Vladimir
They control grabbing builds for a specific version of Scala.
% grabs the dependency exactly as you described it.
%% tacks the Scala version into the resource name to fetch a version for the local Scala build. Extra useful.if you crossbuild for several releases of Scala.
Since 2011, the doc got a bit more complete: "Library dependencies ".
The article "Sbt heiroglyphs and multi-projects explained" from Divan Visagie also details those sbt operators:
% and %% get a little tricky: they define the ids and versions of each library in the sequence , but it’s safe to say that:
"org.scala-tools" % "scala-stm_2.11.1" % "0.3"
Is the equivalent of
"org.scala-tools" %% "scala-stm" % "0.3"
So effectively the extra %% means it figures out what Scala version you are on.
The doc adds:
The idea is that many dependencies are compiled for multiple Scala versions, and you’d like to get the one that matches your project to ensure binary compatibility.
The complexity in practice is that often a dependency will work with a slightly different Scala version; but %% is not smart about that.
So if the dependency is available for 2.10.1 but you’re using scalaVersion := "2.10.4", you won’t be able to use %% even though the 2.10.1 dependency likely works.
If %% stops working, just go see which versions the dependency is really built for, and hardcode the one you think will work (assuming there is one).