【问题标题】:Read jars from lib folder in grails从 grails 中的 lib 文件夹中读取 jars
【发布时间】:2012-02-26 09:48:03
【问题描述】:

我想使用 Apache POI library 解析一个 excel 文件,以将开发模式下的一些数据引导到我的 grails 2.0.1 应用程序中。

我尝试使用 Grails excel-import pluginplugin uninstalls automatically when I execute run-app

因此,我决定暂时不使用插件。首先,我将下一个 jar 复制到 grails 应用程序 lib 文件夹中

$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

我读过我应该在grails-app/conf/BuildConfig.groovy 中声明依赖项。所以,我添加了下一个:

   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'
    }

但是,当我执行 run-app 时,应用程序仍然无法找到 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

我没有使用任何 IDE。欢迎任何反馈!

【问题讨论】:

  • 复制的 jar 中是否包含此类?

标签: grails jar grails-2.0


【解决方案1】:

POI jar 位于公共 Maven 存储库中,因此请尝试以下操作:

  1. 从您的 lib 文件夹中删除 jars
  2. 使用以下命令清理您的构建:grails clean
  3. 在 BuildConfig.groovy 中确保“存储库”闭包包含/未注释“mavenCentral()
  4. 你的依赖看起来没问题(我还没有确认)所以现在试试 run-app

HTH

【讨论】:

    【解决方案2】:

    不要添加编译依赖,而是尝试添加运行时依赖,如下所示。

    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'
    }
    

    【讨论】:

      猜你喜欢
      • 2016-01-06
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 2017-02-25
      • 1970-01-01
      相关资源
      最近更新 更多