Groovletを試してみた
いまさらですが、Groovletを試してみました。
ハローワールド的な内容ですが、すごく簡単にできたのでとてもビックリしました。
フォルダ構成&ソース
以下のような感じにソースとフォルダを用意する。
└webapps └myGroovlets ├Start.groovy └WEB-INF ├web.xml └classes ←とりあえず空フォルダ └groovy ←とりあえず空フォルダ └lib └groovy-all-1.6.3.jar ←置くだけ!
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Groovlet Demonstrator</display-name> <description> Showing the use of Groovlets for Groovy in Action </description> <servlet> <servlet-name>Groovy</servlet-name> <servlet-class>groovy.servlet.GroovyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Groovy</servlet-name> <url-pattern>*.groovy</url-pattern> </servlet-mapping> </web-app>
Start.groovy
html.html { head { title 'Groovlet Demonstrator' } body { h1 'Welcome to the World of Groovlets' } }
めでたしめでたし
「Welcome to the World of Groovlets」と表示されたら成功です。
簡単ですね。*2
groovy-all-1.6.3.jarを置いただけで動くのがすばらしい。