프로젝트에서 다소 한가한 시간이라서 평소 생각만 하던 grails를 만들어보기로 했다.
작은 목표는 커뮤니케이션 포탈을 만들어보는것. (게으른 내게는 큰 목표다... )
-
설치
두가지 방법이 있다. STS 를 설치하여 IDE환경에서 작업하는 것과, 콘솔에서 작업하는 방식- STS 설치방식
- Java SDK 1.5+ 설치여부를 확인. (없으면 먼저 설치.. )
- STS를 다운로드 한다. 주1)
- 설치후 dashboard 화면에서 extensions tab 선택후
Grails support, Groovy Eclipse 를 체크한다. (grails 는 뭔지 모르겠다.. 같이 설치했다.)
- 설치후 리스타팅 하면 완료
참고 : http://www.grails.org/STS+Integration -
콘솔 설치
다운로드 사이트에서 grails를 다운로드 http://www.grails.org/Download
환경변수 셋팅
- java home setting Java SDK 1.5+
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0
# 설치위치 ( unix면 \대신 / )
set GRAILS_HOME=c:\grails-1.3.4
set PATH=%PATH%;%GRAILS_HOME%\bin
- java home setting Java SDK 1.5+
- STS 설치방식
-
-
GRAILS 프로젝트 만들기
- STS에서
File > New > Grails Project ... Done! - 콘솔에서
>grails create-app my-project ... Done!
- STS에서
-
도메인 클래스 만들기
- STS에서
Grails console을 open 주2)
>create-domain-class speaker -
콘솔에서
>grails create-domain-class speaker- // Speaker.groovy 편집
package my.project - class Speaker {
String name
String title
String company
static constraints = {
name(maxSize:20)
title(maxSize:50)
}
}
- // Speaker.groovy 편집
- grails domain 설정
- STS에서
- 콘트롤러 클래스 만들기
-
- STS에서
Grails console을 open
>create-controller my.project.Speaker - 콘솔에서
>grails create-controller my.project.Speaker주3) - grails controller 설정
- STS에서
- 실행
-
- STS에서
프로젝트에서 context menu > run as > grails command(run-app) -
콘솔에서
>grails run-appcf) 실행시 hostname이 한글인 경우 ehcache에서 UnknownHostException 을 발생시키는데 기동에는 문제가 없다.
- STS에서
-
scaffodling template customizing
- 먼저 scaffolding template 을 사이트에 적절하게 변경하는 작업을 수행하는 것이 유용하다.
커맨드 창 또는 grails 콘솔에서
>grails install-templates 를 실행한다.
그러면 src/templates 에 모든 템플릿 파일들이 생성된다. - 해당 파일들에 대해 default 값들을 수정하여 사용하면 유용 ( 표준 주석 등도 만들어 두면 good.. )
- 먼저 scaffolding template 을 사이트에 적절하게 변경하는 작업을 수행하는 것이 유용하다.
-
JSP에서 gsp의 TLD 사용하기
- 최상단에 <%@ taglib prefix="g" uri="/WEB-INF/tld/grails.tld" %> 추가
-
grails -Dserver.port=9000 run-app
http://www.tipstrs.com/tip/12727/Changing-the-port-of-a-Grails-project
jquery : grails install-plugin jquery
http://grails.org/plugin/jquery
주1) 현재 2.3.2가 release 된 상태다. http://www.springsource.com/products/springsource-tool-suite-download
주2) 단축키 Ctrl+Shift+Alt+G 또는 메뉴에서 Navigate > open Grails command prompt
주3) 다시 실행하는 경우 덮어쓸지 물어본다.
참고 사이트
http://www.howardism.org/Technical/Groovy/Grails_Advice.html
http://grailstutorials.com/tutorial
http://greatkim91.tistory.com/
이 글은 스프링노트에서 작성되었습니다.