Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First commit

  • Loading branch information...
commit 718bd9f9f586f9a85932a73c40ea2d2f6e5fdabe 0 parents
Srirangan authored
2  .gitignore
@@ -0,0 +1,2 @@
+
+/target
13 README.md
@@ -0,0 +1,13 @@
+# Simple Scalatra Archetype
+
+An Apache Maven archetype to generate a simple Scalatra webapp.
+
+# Quick Start
+
+ mvn archetype:generate -DarchetypeArtifactId=simple-scalatra-archetype -DarchetypeGroupId=org.scalatra -DarchetypeVersion=1.0-SNAPSHOT -DgroupId={TempGroupId} -DartifactId={TempArtifactId}
+
+ cd {TempArtifactId}
+
+ mvn install
+
+ mvn jetty:run
12 pom.xml
@@ -0,0 +1,12 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.scalatra</groupId>
+ <artifactId>simple-scalatra-archetype</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+</project>
21 src/main/resources/META-INF/maven/archetype.xml
@@ -0,0 +1,21 @@
+<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd">
+
+ <id>scalatra-maven-prototype</id>
+
+ <sources>
+ <source>src/main/scala/MyScalatraFilter.scala</source>
+ </sources>
+
+ <resources>
+ <resource>src/main/webapp/WEB-INF/web.xml</resource>
+ <resource>src/main/webapp/WEB-INF/scalate/layouts/default.scaml</resource>
+ <resource>src/main/webapp/WEB-INF/scalate/templates/hello-scalate.scaml</resource>
+ </resources>
+
+ <testSources>
+ <source>src/test/scala/MyScalatraFilterSuite.scala</source>
+ </testSources>
+
+</archetype>
134 src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,134 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <version>${version}</version>
+
+ <packaging>war</packaging>
+
+ <properties>
+ <scalatra.version>2.0.0.M3</scalatra.version>
+ </properties>
+
+ <build>
+ <finalName>scalatra-maven-prototype</finalName>
+ <sourceDirectory>src/main/scala</sourceDirectory>
+ <testSourceDirectory>src/test/scala</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <version>2.15.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ <configuration>
+ <args>
+ <arg>-make:transitive</arg>
+ <arg>-dependencyfile</arg>
+ <arg>${project.build.directory}/.scala_dependencies</arg>
+ </args>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <useFile>false</useFile>
+ <disableXmlReport>true</disableXmlReport>
+ <includes>
+ <include>**/*Test.*</include>
+ <include>**/*Suite.*</include>
+ </includes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <version>6.1.17</version>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.scalatra</groupId>
+ <artifactId>scalatra-scalate_2.8.1</artifactId>
+ <version>${scalatra.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.scalatra</groupId>
+ <artifactId>scalatra-scalatest_2.8.1</artifactId>
+ <version>${scalatra.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5-20081211</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>0.9.25</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.scalatra</groupId>
+ <artifactId>scalatra_2.8.1</artifactId>
+ <version>${scalatra.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>2.8.1</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>SonatypeNexusSnapshots</id>
+ <name>Sonatype Nexus Snapshots</name>
+ <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
+ </repository>
+ <repository>
+ <id>FuseSourceSnapshotRepository</id>
+ <name>FuseSource Snapshot Repository</name>
+ <url>http://repo.fusesource.com/nexus/content/repositories/snapshots/</url>
+ </repository>
+ <repository>
+ <id>ScalaToolsMaven2Repository</id>
+ <name>Scala-Tools Maven2 Repository</name>
+ <url>http://scala-tools.org/repo-releases/</url>
+ </repository>
+ <repository>
+ <id>scala-tools.org</id>
+ <name>Scala-Tools Maven2 Repository</name>
+ <url>http://scala-tools.org/repo-releases</url>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>scala-tools.org</id>
+ <name>Scala-Tools Maven2 Repository</name>
+ <url>http://scala-tools.org/repo-releases</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
33 src/main/resources/archetype-resources/src/main/scala/MyScalatraFilter.scala
@@ -0,0 +1,33 @@
+package net.srirangan
+
+import org.scalatra._
+import java.net.URL
+import scalate.ScalateSupport
+
+class MyScalatraFilter extends ScalatraFilter with ScalateSupport {
+
+ get("/") {
+ <html>
+ <body>
+ <h1>Hello, world!</h1>
+ Saying hello to Scalatra from Maven.
+ </body>
+ </html>
+ }
+
+ notFound {
+ // If no route matches, then try to render a Scaml template
+ val templateBase = requestPath match {
+ case s if s.endsWith("/") => s + "index"
+ case s => s
+ }
+ val templatePath = "/WEB-INF/scalate/templates/" + templateBase + ".scaml"
+ servletContext.getResource(templatePath) match {
+ case url: URL =>
+ contentType = "text/html"
+ templateEngine.layout(templatePath)
+ case _ =>
+ filterChain.doFilter(request, response)
+ }
+ }
+}
12 src/main/resources/archetype-resources/src/main/webapp/WEB-INF/scalate/layouts/default.scaml
@@ -0,0 +1,12 @@
+-@ val title: String
+-@ val headline: String = title
+-@ val body: String
+
+!!!
+%html
+ %head
+ %title= title
+ %body
+ #content
+ %h1= headline
+ != body
4 src/main/resources/archetype-resources/src/main/webapp/WEB-INF/scalate/templates/hello-scalate.scaml
@@ -0,0 +1,4 @@
+- attributes("title") = "Scalatra: a tiny, Sinatra-like web framework for Scala"
+- attributes("headline") = "Welcome to Scalatra"
+
+Hello, Scalate!
18 src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:web="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
+ <filter>
+ <filter-name>scalatra</filter-name>
+ <filter-class>
+ net.srirangan.MyScalatraFilter
+ </filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>scalatra</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
19 src/main/resources/archetype-resources/src/test/scala/MyScalatraFilterSuite.scala
@@ -0,0 +1,19 @@
+package net.srirangan
+
+import org.scalatra._
+import org.scalatra.test.scalatest._
+
+import org.junit.runner.RunWith
+import org.scalatest.matchers._
+import org.scalatest.junit.JUnitRunner
+
+@RunWith(classOf[JUnitRunner]) // makes test run with Maven Surefire
+class MyScalatraFilterSuite extends ScalatraFunSuite with ShouldMatchers {
+ addFilter(classOf[MyScalatraFilter], "/*")
+
+ test("GET / returns status 200") {
+ get("/") {
+ status should equal (200)
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.