NetBeansã¨Scalaã使ã£ã¦AppEngineããã¨ãã¡ããã¡ãããæ¹æ³
俺ãæ°ããã¢ããªã ããããããããã¤ããããAppSlotã解æ¾ãããã â¦!ã
appengineãããã§ãã§ã·ããâ¦ã§ããâ¦?ãããªãã£ããªãã·ãâ¦ã¯ãå
¥ãããªâ¦?ã
俺ãä»æ¥ã¯Scalaã使ã£ãã¢ããªã±ã¼ã·ã§ã³ãªãã ãã
appengineãããScalaãªãã¦â¦ãããªå¤æ
çãªãã¨â¦ã§ãã§ãã¾ãã ///ã
俺ãããé
ãããã©ãã ? ã©ãã©ãã¢ããªãã¢ãããã¼ãããã¦ããã!ã
appengineãããã¯ãå
¥ãã¾ããâ¦ããããªãã£ããªã¢ããªã±ã¼ã·ã§ã³â¦ãã¤ãã§ãâ¦ã
俺ããããã¹ãã ãã©ãã©ããªã¯ã¨ã¹ããããã£ã¦ãããããªã
appengineããããããããªã«ãªã¯ã¨ã¹ãããããâ¦ãããã£!!SpinUpãã¡ããã
ã£!!ã
俺ãã¾ã ã¾ã ããããããã£!ãã¼ã¿ã¹ãã¢ã«putãã¦ããã£!ã
appengineããããããã!ãã£ãããµãã¡ããã£!!ãã¼ã¿ãâ¦quotaããããµãã¡ãããããã£!!ã
èªåã®é ã®æªãã«çµ¶æãã¾ãããã©ãã¿ã¦ãæé ãã§ãæ¬å½ã«ãã(ry
ããã¯ãã¦ãããScala2.8 + NetBeans6.8ã§ãGoogle App Engine/Javaã®ç°å¢ã®ä½ãæ¹ã«ã¤ãã¦ã¾ã¨ãã¾ããã
NetBeanã§Scala
NetBean6.8å ¥ãã
ã¾ãã¯NetBean6.8ãå
¥ãã¾ããããã¦ã³ãã¼ä¸¼ãã¦ã¤ã³ã¹ã³ã!!
http://netbeans.org/downloads/
NetBeans Scala plugin
次ã«ãNetBeans Scala pluginãå
¥ãã¾ãã
http://wiki.netbeans.org/Scala68v1#Install_with_NetBeans_6.8
ãã¦ã³ãã¼ããããã¡ã¤ã«ãé©å½ãªã¨ãã«è§£åãã¦ããã¾ãã
次ã«ãNetBeansã®ã¡ãã¥ã¼ãã[ãã¼ã«]â[ãã©ã°ã¤ã³]ãé¸ã³ã[ãã¦ã³ãã¼ãæ¸ã¿]ã®ã¿ããéãã¾ãã[ãã©ã°ã¤ã³ã®è¿½å ]ãã¿ã³ãæ¼ãã¦ãå ã»ã©è§£åããNetBeans Scala pluginã®ãã©ã«ãã表示ããã*.nbmãã¡ã¤ã«ãå ¨ã¦é¸æãã¾ãã
ããã§ã¤ã³ã¹ãã¼ã«ãæ¼ãã¨ããã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ããã¾ãã
MaxOSXã®äººã¯ãScalaå®è¡ç°å¢ã®ãã¹ãç°å¢å¤æ°ã«è¨å®ãã¦ããå¿ è¦ãããã¾ãã
NetBeansãã¤ã³ã¹ãã¼ã«ãããã©ã«ã(é常ã¯"/Applications/NetBeans/NetBeans 6.8.app/Contents/MacOS")ã«ãenvironment.plistã¨è¨ããã¡ã¤ã«ã以ä¸ã®å 容ã§ä½ãã¾ãã
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>SCALA_HOME</key> <string>/Users/ozaki/dev/Scala/scala-2.8.0.Beta1-prerelease/rt</string> <key>PATH</key> <string>/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/Users/ozaki/dev/Scala/scala-2.8.0.Beta1-prerelease/rt/bin</string> </dict> </plist>
SCALA_HOMEã«ã¯ãScala2.8ãã¤ã³ã¹ã³ãããã¹ããPATHã«ã¯ãScala2.8ã®binãã£ã¬ã¯ããªã絶対ãã¹ã§è¿½å ãã¾ãããã®ãã¡ã¤ã«ãä½æããããä¸åº¦ãã°ã¢ã¦ãããªãã¨æå¹ã«ãªãã¾ããã®ã§æ³¨æãå¿ è¦ã§ãã
Scala Libraryã®è¿½å
[ãã¼ã«]â[ã©ã¤ãã©ãª]ãé¸ã³ã"æ°è¦ã©ã¤ãã©ãª"ãé¸ã³ã¾ãã
ååã«"Scala28"ã¨å
¥åãã"jar/ãã©ã«ãã追å "ãæ¼ãã¦ãScala 2.8ãã¤ã³ã¹ãã¼ã«ãããã£ã¬ã¯ããªã«ãã"lib/scala-library.jar"ãé¸æãã¦è¿½å ãã¾ãã
Google App Engin Pluginãå ¥ãã
Google App Engine SDK
ã¾ããGoogle App Engine SDKãç¡ããã°ãã¦ã³ãã¼ä¸¼ãã¦ããã¹ãã
Google App Engine Plugin
[ãã¼ã«]â[ãã©ã°ã¤ã³]ãé¸ã³ã[è¨å®]ã®ã¿ããéãã¾ãã[追å ]ãã¿ã³ãæ¼ãã¦ã"http://kenai.com/projects/nbappengine/downloads/download/Latest_NetBeans68/updates.xml"ã追å ãã¾ãã
[使ç¨å¯è½ãªãã©ã°ã¤ã³]ã¿ããéãã¦[ã«ã¿ãã°ãåèªè¾¼]ããã¨ãGoogleAppEngineã®ãã©ã°ã¤ã³ãä¸è¦§ã«è¡¨ç¤ºããã¾ãã®ã§ãå ¨ã¦é¸æãã¦[ã¤ã³ã¹ãã¼ã«]ãã¾ãã
ãã©ã°ã¤ã³ã®ã¤ã³ã¹ãã¼ã«å¾ã«ãGoogleAppEngineã®ãµã¼ãã¼ããµã¼ãã¹ã«è¿½å ãã¾ãã
å·¦å´ã®[ãµã¼ãã¹]ã¿ãã表示ãã"ãµã¼ãã¼"ãå³ã¯ãªãã¯ãã¦[ãµã¼ãã¼ã®è¿½å ]ãé¸ã³ã¾ãã
"Google App Engine"ãé¸æãã¦æ¬¡ã¸ã
"Installation Location"ã«ã¯ãGoogle App Engine SDKã解åãããã£ã¬ã¯ããªãæå®ãã¾ãã
Google App Engine Libraryã®è¿½å
[ãã¼ã«]â[ã©ã¤ãã©ãª]ãé¸ã³ã"æ°è¦ã©ã¤ãã©ãª"ãé¸ã³ã¾ãã
ååã«"AppEngineLibs"ã¨å ¥åãã"jar/ãã©ã«ãã追å "ãæ¼ãã¦ãGoogle App Engine SDKã解åãããã£ã¬ã¯ããªã«ãã"user/appengine-api-1.0-sdk.jar"ãé¸æãã¦è¿½å ãã¾ãã
ãµã³ãã«ããã¸ã§ã¯ããåããã¦ã¿ã
Google App Engine SDKã«ä»å±ãã¦ãããµã³ãã«ã¢ããªãåããã¦ã¿ã¾ãããã
[ããã¸ã§ã¯ã]â[æ°è¦ä½æ]ãé¸ã³ã"ãµã³ãã«"ã®ä¸ã«ãã"Google App Engine"ã®Guest Bookãé¸ã³ã¾ãããã
ã§ããããã¸ã§ã¯ããå®è¡ããã¨ããã©ã¦ã¶ã§åä½ã確èªã§ãã¾ãã
Scalaã§App Engineãåããã¦ã¿ã
Webã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ã
ã§ã¯ãScalaã§App Engineãåããã¦ã¿ã¾ãã ã
[ãã¡ã¤ã«]â[æ°è¦ããã¸ã§ã¯ã]ãé¸ãã§ã"Java Web"ã®"Webã¢ããªã±ã¼ã·ã§ã³"ãé¸æãã¾ãã
ããã¸ã§ã¯ãåãªã©ãå
¥åãã¦ã"ãµã¼ãã¼ã¨è¨å®"ã®ã¨ããã§ãµã¼ãã«"Google App Engine"ãé¸ãã§å®äºã§ãã
Scalaããã¸ã§ã¯ã
Scalaã使ãå ´åãWebã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ãã¨ã¯å¥ã«Scalaããã¸ã§ã¯ããç¨æãã¾ãããã®ããã¸ã§ã¯ããå ã»ã©ä½ã£ãWebã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ãããåç §ãããå½¢ã§ãã
[ãã¡ã¤ã«]â[æ°è¦ããã¸ã§ã¯ã]ãé¸ãã§ã"Scala"ã®"Scala Class Library"ãé¸æãã¾ãã
åºæ¥ãããã¸ã§ã¯ãã®ã©ã¤ãã©ãªãå³ã¯ãªãã¯ãã¦[ã©ã¤ãã©ãªã追å ]ãé¸ã³ã"AppEngineLibs"ã¨"Scala28"ã追å ãã¾ãã
ããã¸ã§ã¯ããâã¯ãªãã¯ãã¦ã[æ°è¦]â[ãã®ä»]ãã"Scala"ã®"Scala Class"ãé¸ãã§æ°è¦ä½æãã¾ãã
å 容ããããªæãã«ãã¾ãã
package testapp class FirstScala { def someMethod() = { "This comes from Scala!!" } }
Webã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ããå¤æ´ãã
Webã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ãã®ã©ã¤ãã©ãªãå³ã¯ãªãã¯ãã¦[ã©ã¤ãã©ãªã追å ]ãé¸ã³ã"AppEngineLibs"ã¨"Scala28"ã追å ãã¾ãã
次ã«ãWebã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ãã®ã©ã¤ãã©ãªãå³ã¯ãªãã¯ãã¦ã[ããã¸ã§ã¯ãã追å ]ãé¸ã³Scalaããã¸ã§ã¯ãã追å ãã¾ãã
"Webãã¼ã¸"ã«ããindex.jspãä¿®æ£ãã¾ãã
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="testapp.FirstScala"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World!</h1> <p>Test: <%= new FirstScala().someMethod() %></p> </body> </html>
å®è¡
Webã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ããå®è¡ããã¨ããã©ã¦ã¶ã«ç»é¢ã表示ããã¾ãã
ããããã§ãSCALA_HOMEãèªã¿è¾¼ããªãã¨ããAntã®ã¨ã©ã¼ãåºãå ´åã¯ã Scalaããã¸ã§ã¯ãã®"nbproject/build-impl.xml"ãéãã-init-privateã¿ã¼ã²ãããªãã§scala.homeã絶対ãã¹ã§è¨å®ããããã«ãã¦ã¿ã¦ãã ããã
<target depends="-pre-init" name="-init-private"> <property file="nbproject/private/config.properties"/> <property file="nbproject/private/configs/${config}.properties"/> <property file="nbproject/private/private.properties"/> <property environment="env"/> <condition property="scala.home" value="${env.SCALA_HOME}"> <isset property="env.SCALA_HOME"/> </condition> <property name="scala.home" value="/Users/ozaki/dev/Scala/scala-2.8.0.Beta1-prerelease/rt"/> <property name="scala.lib" value="${scala.home}/lib"/> <fail unless="scala.home"> You must set SCALA_HOME or environment property and append "-J-Dscala.home=scalahomepath" property to the end of "netbeans_default_options" in NetBeansInstallationPath/etc/netbeans.conf to point to Scala installation directory. </fail> <property name="scala.compiler" value="${scala.lib}/scala-compiler.jar"/> <property name="scala.library" value="${scala.lib}/scala-library.jar"/> <taskdef resource="scala/tools/ant/antlib.xml"> <classpath> <pathelement location="${scala.compiler}"/> <pathelement location="${scala.library}"/> </classpath> </taskdef> </target>