Read jars from lib folder in grails

ぃ、小莉子 提交于 2019-12-10 10:58:27

问题


I want to parse an excel file using the Apache POI library to boot strap some data in development mode into my grails 2.0.1 application.

I've tried to use the Grails excel-import plugin but the plugin uninstalls automatically when I execute run-app.

Because of that I decided to got ahead without the plugin for now. First I have copied the next jars into the grails application lib folder

$ls -la lib
poi-3.7-20101029.jar
poi-ooxml-3.7-20101029.jar
poi-ooxml-schemas-3.7-20101029.jar
xmlbeans-2.3.0.jar

I've read that I should declare the dependency in grails-app/conf/BuildConfig.groovy. So, I added the next:

   dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
        compile ('org.apache.poi:poi:3.7', 'org.apache.poi:poi-ooxml:3.7')  

        // runtime 'mysql:mysql-connector-java:5.1.16'
    }

However when I execute run-app the application is still not able to find the jars.

grails> run-app
| Compiling 76 source files

| Compiling 30 source files.
| Error Compilation error: startup failed:
UMEExcelImporter.groovy: 8: unable to resolve class org.apache.poi.xssf.usermodel.XSSFSheet
 @ line 8, column 1.
   import org.apache.poi.xssf.usermodel.XSSFSheet
   ^

UMEExcelImporter.groovy: 7: unable to resolve class org.apache.poi.xssf.usermodel.XSSFWorkbook
 @ line 7, column 1.
   import org.apache.poi.xssf.usermodel.XSSFWorkbook
   ^

UMEExcelImporter.groovy: 9: unable to resolve class org.apache.poi.xssf.usermodel.XSSFRow
 @ line 9, column 1.
   import org.apache.poi.xssf.usermodel.XSSFRow

I am not using any IDE. Any feedback is welcome!


回答1:


The POI jars are on public Maven repo's so try this:

  1. Remove the jars from your lib folder
  2. Clean your build with: grails clean
  3. In you BuildConfig.groovy ensure that the "repositories" closure has "mavenCentral()" included/uncommented
  4. Your dependency looks ok (I have not confirmed it) so now try the run-app

HTH




回答2:


instead of adding compile dependency, try adding runtime dependency as follows.

dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
        runtime ('org.apache.poi:poi:3.7', 'org.apache.poi:poi-ooxml:3.7')  

    // runtime 'mysql:mysql-connector-java:5.1.16'
}


来源:https://stackoverflow.com/questions/9452090/read-jars-from-lib-folder-in-grails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!