If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!
Showing posts with label GitBash. Show all posts
Showing posts with label GitBash. Show all posts

Sunday, December 23, 2012

Getting Play2.0.x to work with Git Bash on Windows

I unzipped play2.0.4 and created a PLAY_HOME variable. I also made sure to add PLAY_HOME to my PATH variable.

nxp10009@NXL01366 /c/development/play-2.0.4
$ echo $PLAY_HOME
C:\development\play-2.0.4

When I tried to run play from the Git Bash shell I ran into below exception. In the past I didn't bother that much and just used the DOS shell as a workaround. But I like to work from one shell only so time to look for a solution.
nxp10009@NXL01366 /c/workspaces/scala
$ play
Error during sbt execution: Could not find configuration file 'c:/development/play-2.0.4/framework/sbt/play.boot.properties'.  Searched:
        file:/c:/workspaces/scala/
        file:/C:/Users/nxp10009/
        file:/C:/development/play-2.0.4/framework/sbt/

Luckily someone created a patch to resolve this issue. You can download the gist and unzip it to some folder. It will contain a file named play_cgywin.patch. So it's matter of applying the patch from within Git Bash. It will log an error but play will work nonetheless.
nxp10009@NXL01366 /c/development/play-2.0.4
$ patch -p1 < c:/tmp/play_cygwin.patch
patching file `framework/build'
Hunk #1 FAILED at 8.
1 out of 1 hunk FAILED -- saving rejects to framework/build.rej
patching file `play'


nxp10009@NXL01366 /c/workspaces/scala
$ play
Getting play console_2.9.1 2.0.4 ...
:: retrieving :: org.scala-sbt#boot-app
        confs: [default]
        5 artifacts copied, 0 already retrieved (3667kB/83ms)
       _            _
 _ __ | | __ _ _  _| |
| '_ \| |/ _' | || |_|
|  __/|_|\____|\__ (_)
|_|            |__/

play! 2.0.4, http://www.playframework.org

Sunday, December 9, 2012

SBT Quick start - Part 1

Now that I have Scala and SBT working from GitBash we will setup our first demo project.
$ mkdir demo
$ cd demo
$ mkdir -p src/{main,test}/{java,scala,resources}

Create a script hw.scala and place it under demo/src/scala
/*********** hw.scala ***************/
object Hi {
  def main(args: Array[String]) = println("Demo application says HELLO!")
}

now run sbt -> Running sbt with no command line arguments starts it in interactive mode.
nxp10009@NXL01366 /c/workspaces/pelssers/demo
$ sbt
[info] Set current project to default-8388aa (in build file:/C:/workspaces/pelssers/demo/)
> exit  

We still have to create a build.sbt in the project root so let's do this first
name := "demo"

version := "1.0-SNAPSHOT"

scalaVersion := "2.9.2"

If we now rerun sbt again everything seems ok
$ sbt
[info] Set current project to demo (in build file:/C:/workspaces/pelssers/demo/)
> exit

You will now see sbt created a project folder for you. Here we will create a new build.properties file
nxp10009@NXL01366 /c/workspaces/pelssers/demo
$ ls -la
total 3
drwxr-xr-x    6 nxp10009 Administ        0 Dec  9 15:13 .
drwxr-xr-x    8 nxp10009 Administ     4096 Dec  9 15:04 ..
-rw-r--r--    1 nxp10009 Administ       70 Dec  9 15:04 build.sbt
drwxr-xr-x    3 nxp10009 Administ        0 Dec  9 15:13 project
drwxr-xr-x    4 nxp10009 Administ        0 Dec  9 15:05 src
drwxr-xr-x    3 nxp10009 Administ        0 Dec  9 15:12 target


$ cd project
$ vi build.properties


sbt.version=0.12.0
Enabling continous build and test
> ~ compile
[success] Total time: 0 s, completed Dec 9, 2012 3:32:39 PM
1. Waiting for source changes... (press enter to interrupt)

Now edit the hw.scala and make a little change:
object Hi {
  def main(args: Array[String]) = println("Demo application says HELLO again!")
}

[info] Compiling 1 Scala source to C:\workspaces\pelssers\demo\target\scala-2.9.2\classes...
[success] Total time: 1 s, completed Dec 9, 2012 3:33:02 PM
2. Waiting for source changes... (press enter to interrupt)

Getting Git Bash and Scala working on windows

I found a great blog post about fixing issues. I already avoid using spaces in directory names so I only ran into the last issue:
nxp10009@NXL01366 /c/development/scala/scala-2.9.2/bin
$ scala
Exception in thread "main" java.lang.NoClassDefFoundError: scala/tools/nsc/MainGenericRunner
Caused by: java.lang.ClassNotFoundException: scala.tools.nsc.MainGenericRunner
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: scala.tools.nsc.MainGenericRunner.  Program will exit.

So I only need to create a bash script and add an alias to fix the issue
nxp10009@NXL01366 ~
$ cd ~

nxp10009@NXL01366 ~
$ pwd
/c/Users/nxp10009

nxp10009@NXL01366 ~
$ vi .bashrc

alias scala='scala -nobootcp'

Now exit Git Bash and open a new shell:
nxp10009@NXL01366 ~
$ scala
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_32).
Type in expressions to have them evaluated.
Type :help for more information.

scala>