Mac OS X 또는Ubuntu 등의 리뉵스에 Grails 2.1.1 을 설치하는 방법을 알아본다

Grais 를 설치하기 위해서는 JDK(Java Development Kit) 6.0 이상이 ㅁㄴ저 설치되어 있으면 충분하다. (Groovy는 설치되어 있지 않아도 된다.)

Grails 홈페이지는 http://grails.org 이다. 현재 최신 릴리즈는 Grails 2.1.1 이다. gails-2.1.1.zip 파일을 다운받아서 압축 해제한 다음 적당한 곳으로 옮긴다.

$ unzip grails-2.1.1.zip

$ sudo mv grails=2.1.1 /usr/local/grails-2.1.1

한경변수 GRAILS_HOME, JAVA_HOME, PATH 를 잡아 준다.

$ sudo vi /etc/profile

하여 다음 세 줄을 추가한다.

JAVA_HOME=................' export JAVA_HOME

GAILS_HOME=/usr/local/grails-2.1.1; export GRAILS_HOME

PATH=$GRAILS_HOME/bin:$JAVA_HOME/bin:$PATH; export PATH


변경된 환경변수의 값을 현재의 ㅌ미널 셀에 적요이킨다.

$ source /etc/profile


홈 폴더(~) 밑에 test 폴더를 만들고 또 그 밑에 테스트르 위한 grails 폴더를 만든 후 ~/test/grails 폴더로 간다.


$ mkdir ~/test
$ mkdir ~/test/grals
$ cd ~/test/grails


~/test/grails 폴더에서 helloworld 애플리케이션 생성한다.

$ grails create-app helloworld
 

* grails 애플리케이션 실행하기

~/test/grails 폴더의 서브폴더 helloworld 러 가서 Grails 애플리케이션을 실행시킨다.

$ cd helloworld

$ grails run-app


 웹브라우저로 http://localhost:8080/helloworld 를 방문한다.



 

* 첫번 째 컨트롤러 만들기

$ grails create-controller hello

[grails-app/contollers/helloworld/HelloController.groovy 파일의 내용]

package helloworld

class HelloController {

    def index() { }

    def world() {
        render "Hello, world! <br />\n${new Date()}<br />\n"
        render "안녕하세요? GRails 2.1.1<br />\n"
    }
}

 

$ grails run-app

웹브라우저로 http://localhost:8080/helloworld/hello/world 를 방문한다.


 

 

 

Posted by Scripter
,

 

윈도우에서 Grails 2.1.1 을 설치한 후, 한경변수 GRAILS_HOME, JAVA_HOME, PATH 가 모두 잡혔는데도 불구하고 "rails create-app" 명령시 에러

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre7

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

가 나는 경우가 있다. (리눅스/유닉스에서는 이런 경우가 없음 )

이럴 때는 startGrails.bat 파일을 텍스트 편집기로 열어서 42번째 줄

%COMMAND_COM% /C DIR "%JAVA_HOME%" 2>&1 | %FIND_EXE% /I /C "%JAVA_HOME%" >nul

@rem %COMMAND_COM% /C DIR "%JAVA_HOME%" 2>&1 | %FIND_EXE% /I /C "%JAVA_HOME%" >nul

로 고쳐서 주석처리 한다. 그러면 "grails create-app" 명령이 잘 된다.

다음은 C:\test\grails 폴더에서 helloworld 애플리케이션을 성공적으로 생성한 경우의 출력이다.

C:\test\grails> grails create-app helloworld

| Downloading: c:\GRails211\lib\org.springframework.uaa\org.springframework.uaa.
| Downloading: c:\GRails211\lib\com.googlecode.json-simple\json-simple\ivy-1.1.x
| Downloading: c:\GRails211\lib\com.googlecode.concurrentlinkedhashmap\concurren
| Downloading: c:\GRails211\lib\org.springframework.uaa\org.springframework.uaa.
| Downloading: c:\GRails211\lib\com.google.protobuf\protobuf-java\jars\protobuf-
| Downloading: c:\GRails211\lib\com.googlecode.json-simple\json-simple\jars\json
| Downloading: c:\GRails211\lib\org.bouncycastle\bcpg-jdk15\jars\bcpg-jdk15-1.45
| Downloading: c:\GRails211\lib\org.bouncycastle\bcprov-jdk15\jars\bcprov-jdk15-
| Downloading: c:\GRails211\lib\org.springframework\spring-test\jars\spring-test
| Downloading: c:\GRails211\lib\com.googlecode.concurrentlinkedhashmap\concurren
| Downloading: c:\GRails211\lib\org.apache.ant\ant-launcher\jars\ant-launcher-1.
| Downloading: c:\GRails211\lib\org.apache.ant\ant-junit\jars\ant-junit-1.8.2.ja
| Downloading: c:\GRails211\lib\org.apache.tomcat.embed\tomcat-embed-core\jars\t
| Downloading: c:\GRails211\lib\org.apache.tomcat.embed\tomcat-embed-jasper\jars
| Downloading: c:\GRails211\lib\org.apache.tomcat.embed\tomcat-embed-logging-log
| Downloading: c:\GRails211\lib\commons-beanutils\commons-beanutils\ivy-1.8.3.xm
| Downloading: c:\GRails211\lib\commons-validator\commons-validator\ivy-1.3.1.xm
| Downloading: c:\GRails211\lib\commons-collections\commons-collections\ivy-3.2.
| Downloading: c:\GRails211\lib\org.hibernate.javax.persistence\hibernate-jpa-2.
| Downloading: c:\GRails211\lib\commons-fileupload\commons-fileupload\ivy-1.2.2.
| Downloading: c:\GRails211\lib\org.codehaus.groovy\groovy-all\jars\groovy-all-1
| Downloading: c:\GRails211\lib\commons-beanutils\commons-beanutils\jars\commons
| Downloading: c:\GRails211\lib\commons-validator\commons-validator\jars\commons
| Downloading: c:\GRails211\lib\aopalliance\aopalliance\jars\aopalliance-1.0.jar
| Downloading: c:\GRails211\lib\commons-codec\commons-codec\jars\commons-codec-1
| Downloading: c:\GRails211\lib\commons-collections\commons-collections\jars\com
| Downloading: c:\GRails211\lib\commons-lang\commons-lang\jars\commons-lang-2.6.
| Downloading: c:\GRails211\lib\org.hibernate.javax.persistence\hibernate-jpa-2.
| Downloading: c:\GRails211\lib\org.springframework\spring-core\jars\spring-core
| Downloading: c:\GRails211\lib\org.springframework\spring-aop\jars\spring-aop-3
| Downloading: c:\GRails211\lib\org.springframework\spring-aspects\jars\spring-a
| Downloading: c:\GRails211\lib\org.springframework\spring-asm\jars\spring-asm-3
| Downloading: c:\GRails211\lib\org.springframework\spring-beans\jars\spring-bea
| Downloading: c:\GRails211\lib\org.springframework\spring-context\jars\spring-c
| Downloading: c:\GRails211\lib\org.springframework\spring-context-support\jars\
| Downloading: c:\GRails211\lib\org.springframework\spring-expression\jars\sprin
| Downloading: c:\GRails211\lib\org.springframework\spring-jdbc\jars\spring-jdbc
| Downloading: c:\GRails211\lib\org.springframework\spring-jms\jars\spring-jms-3
| Downloading: c:\GRails211\lib\org.springframework\spring-orm\jars\spring-orm-3
| Downloading: c:\GRails211\lib\org.springframework\spring-tx\jars\spring-tx-3.1
| Downloading: c:\GRails211\lib\org.springframework\spring-web\jars\spring-web-3
| Downloading: c:\GRails211\lib\org.springframework\spring-webmvc\jars\spring-we
| Downloading: c:\GRails211\lib\org.grails\grails-datastore-gorm\jars\grails-dat
| Downloading: c:\GRails211\lib\org.grails\grails-datastore-core\jars\grails-dat
| Downloading: c:\GRails211\lib\org.grails\grails-datastore-simple\jars\grails-d
| Downloading: c:\GRails211\lib\org.aspectj\aspectjweaver\jars\aspectjweaver-1.6
| Downloading: c:\GRails211\lib\commons-fileupload\commons-fileupload\jars\commo
| Downloading: c:\GRails211\lib\commons-dbcp\commons-dbcp\jars\commons-dbcp-1.4.
| Downloading: c:\GRails211\lib\commons-pool\commons-pool\jars\commons-pool-1.5.
| Downloading: c:\GRails211\lib\net.sf.ehcache\ehcache-core\jars\ehcache-core-2.
| Downloading: c:\GRails211\lib\org.slf4j\jcl-over-slf4j\jars\jcl-over-slf4j-1.6
| Downloading: c:\GRails211\lib\org.slf4j\jul-to-slf4j\jars\jul-to-slf4j-1.6.2.j
| Created Grails Application at C:\test\grails/helloworld

 

grails 애플리케이션 실행하기

C:\test\grails> cd helloworld

C:\test\grails\helloworld> grails run-app

 웹브라우저로 http://localhost:8080/helloworld 를 방문한다.

 

 

첫번째 컨트롤러 만들기

C:\test\grails\helloworld> grails create-controller hello

[grails-app/contollers/helloworld/HelloController.groovy 파일의 내용]

package helloworld

class HelloController {

    def index() { }

    def world() {
        render "Hello, world! <br />\n${new Date()}<br />\n"
        render "안녕하세요? GRails 2.1.1<br />\n"
    }
}

 

C:\test\grails\helloworld> grails run-app

웹브라우저로 http://localhost:8080/helloworld/hello/world 를 방문한다.

 

 

 

Posted by Scripter
,