Pergunta

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!

Foi útil?

Solução

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

Outras dicas

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'
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top