2014-05-11 13 views
0

我有一些示例代碼在它不能找到資源文件夾中的SpringBeans.groovy,但我可以找到log4j.properties - 任何想法爲什麼它不會找到文件?

static main(args) { 
    // Load the spring beans 
    BeanBuilder beanBuilder = new BeanBuilder() 
    //beanBuilder.loadBeans("classpath:SpringBeans.groovy") 
    beanBuilder.loadBeans("file:src/main/resources/SpringBeans.groovy") 
def res = new ClassPathResource ("log4j.properties") 
    File fprop = res.getFile() 
    assert fprop.exists() 

爲beanBuilder.loadBeans我有使用固定的絕對文件URI一個簡單的彈簧文件。我曾嘗試在同一文件夾讀取log4j.properties和工作使用使用ClassPathResource - 並且斷言是罰款

,但如果我嘗試這個尋找SpringBeans.groovy文件

def res = new ClassPathResource ("SpringBeans.groovy") 
File fprop = res.getFile() 
assert fprop.exists() 

也在資源文件夾的根目錄 - 斷言失敗。

爲了讓loadBeans工作,我必須放入一個絕對文件:URI,我想使用classpath窗體 - 但是這找不到它。

爲什麼我可以看到log4j.properties而不是SpringBeans.groovy文件?

任何幫助感激地接受

我已經加入到之後的gradle我的構建文件,以確保我得到的資源目錄。和Eclipse顯示了資源目錄也包含enter code here

sourceSets { 
    main { 
     groovy { 
      srcDir 'src/main/groovy' 
     } 
     resources { 
      srcDir 'src/main/resources' 
     } 
    } 
} 

回答

0

儘管Eclipse將治療log4j.properties文件作爲一種資源,簡單地將其複製到輸出文件夾,SpringBeans.groovy將被編譯,你應該在輸出文件夾中找到SpringBeans.class而不是.groovy文件。
Eclipse允許您定義Groovy腳本文件夾。與定義的模式相匹配的Groovy文件不會被編譯並複製到輸出文件夾。
要配置Groovy腳本文件夾,請轉至首選項 - > Groovy - >編譯器並選中「啓用腳本文件夾支持」。您還可以從項目屬性中定義項目特定的行爲。

+0

輝煌 - 謝謝 - 我看過那一節,​​並沒有真正意識到它做了什麼,所以一直沒有改變。啓用它並在* .groovy上留下複選標記,然後重新生成。和羅,並保持腳本得到放入輸出bin目錄感謝這麼多 –