casualjim
9/10/2011 - 3:17 PM

gistfile1.scala

± ivan@azkaban:~/temp/gist-1208309 [ruby-1.9.2-p180]  
git:(master) ✗ !? » ./scalatra hello_world
the classpath:
/Users/ivan/temp/gist-1208309/./dist/jetty-continuation-8.0.1.v20110908.jar:/Users/ivan/temp/gist-1208309/./dist/jetty-http-8.0.1.v20110908.jar:/Users/ivan/temp/gist-1208309/./dist/jetty-io-8.0.1.v20110908.jar:/Users/ivan/temp/gist-1208309/./dist/jetty-security-8.0.1.v20110908.jar:/Users/ivan/temp/gist-1208309/./dist/jetty-server-8.0.1.v20110908.jar:/Users/ivan/temp/gist-1208309/./dist/jetty-servlet-8.0.1.v20110908.jar:/Users/ivan/temp/gist-1208309/./dist/jetty-util-8.0.1.v20110908.jar:/Users/ivan/temp/gist-1208309/./dist/jetty-webapp-8.0.1.v20110908.jar:/Users/ivan/temp/gist-1208309/./dist/jetty-xml-8.0.1.v20110908.jar:/Users/ivan/temp/gist-1208309/./dist/scalatra_2.9.1-2.1.0-SNAPSHOT.jar:/Users/ivan/temp/gist-1208309/./dist/servlet-api-3.0.20100224.jar
Please wait while scalatra gets ready for business...
<script>:2: error: object scalatra is not a member of package org
import org.scalatra._
           ^
<console>:5: error: not found: type Main$$anon$1$ServletLoader
  var value: Main$$anon$1$ServletLoader = _
             ^
<console>:6: error: not found: type Main$$anon$1$ServletLoader
  def set(x: Any) = value = x.asInstanceOf[Main$$anon$1$ServletLoader]
                                           ^
<console>:10: error: not found: value scalatraApp
val $ires0 = scalatraApp.app
             ^
<console>:7: error: not found: value scalatraApp
       scalatraApp.app = new HelloServlet
       ^
java.lang.IllegalArgumentException
	at org.eclipse.jetty.servlet.ServletHolder.setServlet(ServletHolder.java:127)
	at org.eclipse.jetty.servlet.ServletHolder.<init>(ServletHolder.java:102)
	at Main$$anon$1.<init>(scalatra:57)
	at Main$.main(scalatra:1)
	at Main.main(scalatra)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:78)
	at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:24)
	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:88)
	at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:78)
	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
	at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33)
	at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40)
	at scala.tools.nsc.ScriptRunner.scala$tools$nsc$ScriptRunner$$runCompiled(ScriptRunner.scala:171)
	at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner.scala:188)
	at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner.scala:188)
	at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply$mcZ$sp(ScriptRunner.scala:157)
	at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:131)
	at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:131)
	at scala.tools.nsc.util.package$.waitingForThreads(package.scala:26)
	at scala.tools.nsc.ScriptRunner.withCompiledScript(ScriptRunner.scala:130)
	at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:188)
	at scala.tools.nsc.ScriptRunner.runScriptAndCatch(ScriptRunner.scala:201)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:58)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
#!/bin/sh

curr=`dirname $0`/dist

cp=`echo $(pwd)/$curr/*.jar|sed 's/ /:/g'`
echo "the classpath:"
echo $cp
exec scala -classpath $cp $0 $@

!#

import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.handler._
import org.eclipse.jetty.webapp.WebAppContext
import org.eclipse.jetty.server.nio.SelectChannelConnector
import org.eclipse.jetty.servlet._
import tools.nsc.interpreter._
import tools.nsc.Settings
import io.Source
import java.io.File
import org.scalatra._


trait PlaceHolder

println("Please wait while scalatra gets ready for business...")
val code = """
import org.scalatra._
class HelloServlet extends ScalatraServlet {

%s

}
"""

val fileContent = Source.fromFile(new File("./" + args(0) + ".scalatra")).getLines().filter(_.nonEmpty).map("  " + _).mkString("\n  ")
val fullCode = code format fileContent

val server = new Server
server setGracefulShutdown 5000

val connector = new SelectChannelConnector
connector setPort 4567
connector setMaxIdleTime 90000
server addConnector connector

class ServletLoader {
  var app: ScalatraServlet = null
}
val app = new ServletLoader

val settings = new Settings()
settings.embeddedDefaults(app.getClass.getClassLoader)
val i = new IMain(settings)
i.compileString(fullCode)


i beQuietDuring {
  i.bind[ServletLoader]("scalatraApp", app)
  i.interpret("scalatraApp.app = new HelloServlet")
}

val dynContext = new WebAppContext
dynContext setContextPath "/"
dynContext setResourceBase "."
dynContext setParentLoaderPriority true
dynContext addServlet (new ServletHolder(app.app), "/*")
dynContext addServlet (new ServletHolder(new DefaultServlet()), "/")

val contexts = new ContextHandlerCollection
contexts setHandlers Array(dynContext)
server setHandler contexts

println("Starting server on 4567")

sys addShutdownHook {
  println("Scalatra bids you farewell")
}

server.start()
server.join()