You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Eelco Hillenius <ee...@gmail.com> on 2007/12/14 08:29:36 UTC

Wicket + Scala + Eclipse hack

Hi,

I saw on message from someone having problems to get Wicket + Scala +
Eclipse working together on one of the zillion mailing lists I'm on,
but I don't remember which one, nor can I find it back with Google.
Anyway, in case that person or anyone else with the same problems is
reading this list, here you go.

The problem is that the Eclipse Scala plugin doesn't properly copy
resources to the class path. That's a problem with Wicket, since we
need to have those markup files that come with the component
definitions copied. The solution is simple: add a Java builder in
front (before, not after, as that will clear your just compiled scala
classes from the class path) of the Scala builder. This is how your
.project file then looks:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
       <name>your-project-name</name>
       <comment></comment>
       <projects></projects>
       <buildSpec>
               <buildCommand>
                       <name>org.eclipse.jdt.core.javabuilder</name>
               </buildCommand>
               <buildCommand>
                       <name>ch.epfl.lamp.sdt.core.scalabuilder</name>
                       <arguments></arguments>
               </buildCommand>
       </buildSpec>
       <natures>
               <nature>ch.epfl.lamp.sdt.core.scalanature</nature>
               <nature>org.eclipse.jdt.core.javanature</nature>
       </natures>
</projectDescription>


And now that we're on the topic... let's build a quick HelloWorld app
(I'll leave the packages for your imagination:

First, the Jetty runner:

import org.mortbay.jetty.Server
import org.mortbay.jetty.webapp.WebAppContext

object JettyRunner {

   def main(args: Array[String]) {
     val server = new Server(8080)
     val web = new WebAppContext(server, "src/main/webapp", "/scalatest")
     server.start()
     server.join()
   }
}

Your application class:

import org.apache.wicket._
import org.apache.wicket.protocol.http._

class ScalaExampleApp extends WebApplication {

 override def getHomePage = classOf[Index]

 protected override def init : Unit = {
   super.init
   mountBookmarkablePage("index", classOf[Index])
 }
}

The Index page:

import org.apache.wicket.markup.html._
import org.apache.wicket.markup.html.basic._

class Index extends WebPage {
 add(new Label("label", "Hi there!"))
}

with HTML:

<html>
       <body>
               <span wicket:id="label">[label]</span>
       </body>
</html>

and that's it: your first running Wicket/ Scala app.

This would be roughly the .classpath file you need with your project
(adjust to your liking):

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
       <classpathentry kind="src" path="src/main/scala" />
       <classpathentry kind="con"
               path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER" />
       <classpathentry kind="con"
               path="org.eclipse.jdt.launching.JRE_CONTAINER" />
       <classpathentry kind="var"
               path="M2_REPO/javax/portlet/portlet-api/1.0/portlet-api-1.0.jar"
/>
       <classpathentry kind="var"
               path="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar"
               sourcepath="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.3-sources.jar"
/>
       <classpathentry kind="var"
               path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"
               sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar" />
       <classpathentry kind="var"
               path="M2_REPO/org/apache/portals/bridges/portals-bridges-common/1.0.3/portals-bridges-common-1.0.3.jar"
/>
       <classpathentry kind="var"
               path="M2_REPO/org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2.jar"
               sourcepath="M2_REPO/org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2-sources.jar"
/>
       <classpathentry kind="var"
               path="M2_REPO/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2.jar"
               sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2-sources.jar"
/>
       <classpathentry kind="var"
               path="M2_REPO/log4j/log4j/1.2.13/log4j-1.2.13.jar"
               sourcepath="M2_REPO/log4j/log4j/1.2.13/log4j-1.2.13-sources.jar"
/>
       <classpathentry kind="var"
               path="M2_REPO/org/mortbay/jetty/jetty/6.1.5/jetty-6.1.5.jar"
               sourcepath="M2_REPO/org/mortbay/jetty/jetty/6.1.5/jetty-6.1.5-sources.jar"
/>
       <classpathentry kind="var"
               path="M2_REPO/org/mortbay/jetty/jetty-util/6.1.5/jetty-util-6.1.5.jar"
               sourcepath="M2_REPO/org/mortbay/jetty/jetty-util/6.1.5/jetty-util-6.1.5-sources.jar"
/>
       <classpathentry kind="var"
               path="M2_REPO/org/mortbay/jetty/servlet-api-2.5/6.1.5/servlet-api-2.5-6.1.5.jar"
               sourcepath="M2_REPO/org/mortbay/jetty/servlet-api-2.5/6.1.5/servlet-api-2.5-6.1.5-sources.jar"
/>
       <classpathentry kind="var"
               path="M2_REPO/org/mortbay/jetty/jetty-management/6.1.5/jetty-management-6.1.5.jar"
               sourcepath="M2_REPO/org/mortbay/jetty/jetty-management/6.1.5/jetty-management-6.1.5-sources.jar"
/>
       <classpathentry combineaccessrules="false" kind="src"
               path="/wicket" />
       <classpathentry kind="output" path="target/classes" />
</classpath>


Have fun, and if you really want to see the potential of Scala +
Wicket, look at what Databinder-Nathan is playing with:
http://technically.us/code/x/the-awesomeness-of-scala-is-implicit/

Eelco

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org