블로그 이미지
lahuman

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

05-21 03:36

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
  • total
  • today
  • yesterday

'프로그래밍/groovy'에 해당되는 글 1건

  1. 2007.03.08 groovy Eclipse Plugin 설치
2007. 3. 8. 15:10 프로그래밍/groovy

* 이클립스 3.2 기준


[Groovy]

- 파이선, 루비와 비슷한 자바문법 기반으로 동작하는 스크립트 언어


Main Groovy Site : http://www.codehaus.org/

Main Grails Site : http://grails.org/

Grooyv Portal : http://aboutgroovy.com/


참고글1 : http://www.zdnet.co.kr/services/story/print/0,39035309,39132353,00.htm

참고글2 : http://www.zdnet.co.kr/services/story/print/0,39035309,39134013,00.htm



[설치]

1.  Help -> Software Updates -> Find and Install -> Search For New Features

2.  New Remote Site 선택

3.  Name 필드에 적당히 입력 (ex: Groovy)

4.  URL field 에 아래와 같이 입력후 OK  선택    

     http://dist.codehaus.org/groovy/distributions/update/

5.  몇가지 화면설정후 install all 선택

 
 
[Groovy 프로젝트 생성]
1. File -> New -> Project

2. Java Project 로 프로젝트 생성 (소스폴더 생성)

3. 생성된 프로젝트명을 마우스 우측 클릭후 나타나는 팝업메뉴에서 Add Groovy Nature 선택

4. 프로젝트명 우측클릭후 나타나나느 팝업메뉴에서 properties 선택

5. groovy Project Properties 에서 Groovy compiler output location 입력 (ex: bin-groovy)


[테스트]

src폴더에 Test.groovy 소스를 작성


1. 소스명을 마무스 우측클릭한후 팝업메뉴에서 Run as -> Run 선택

2. 우측트리에서 groovy를 선택한후 new launch configuration 버튼 클릭.

3. 좌측 Groovy Main 탭에서 Main class 필드에 소스명을 입력 (ex: Test)

4. Run 선택


// Test.groovy

//-----------------------------------------------------

println "### 리스트 예제 ###"

def list = ["Rod", "Phil", "James", "Chris"]
def shorts = list.findAll { it.size() < 5 }
shorts.each { println it }

z=[1,3,5];
z.add(-1)
z<<7
println z


println "### 맵 예제 ###"

z= ["일":1, "이":2, "삼":3]
z.each {
    print it.key + ":" + it.value + " "   
}
println ""


println "### 함수 예제 ###"

def square(x)
{
    x*x // return x*x
}

println "square(10) = " + square(10)

   
println "### closure예제 ###"
x = 123
y = 100
c= {println "${it + y }"}  // it 는 디폴트 인자
c(x)
c.call(x)

//-----------------------------------------------------          
         


//와한글만세.groovy 

//-------------------------------------------------------

class 와한글만세 {

    와한글만세() { println "한글이 제일 좋다." }   
   
    def 외쳐봐() { println "세종대왕님 감사합니다." }       
    def 읽어봐(숫자) { 지도[숫자] }    
    def static 지도 = [1:'일', 2:'이', 3:'삼', 4:'사', 5:'오']       
   
    static void main(args) {            
      def 만세 = new 와한글만세()
      만세.외쳐봐()           
      println 지도[1]
      println 만세.읽어봐(3)          
    }
}

//------------------------------------------------------

실행결과 :

한글이 제일좋다

세종대왕님 감사합니다.

//------------------------------------------------------



//PrimeNumber.groovy (소수 구하기)

--------------------------------------------------------

x = 100

y = []
 
for (i in 0..x)
    y[i] = i;


y[0] = 0;
y[1] = 0;


for (i in 2..Math.sqrt(x).intValue())

{

     j = 2


     while (i*j <= x)
    {
        y[i*j] = 0
        j++
    }
}

cnt = 1;


y.each
{
    if(y[it] != 0)
    {
          print y[it] + " ";  
          if (cnt % 20 == 0) {
              println " ";        
          }
     
          cnt++;
    }
}
println ""
println "${x} 까지 소수의 개수는 " + cnt

//---------------------------------------------------


출처 : http://blog.naver.com/paro01?Redirect=Log&logNo=100033486525



posted by 알 수 없는 사용자