0

我在 Windows 上使用 Grails 2.3.5,并使用命令行中的 grails create-app 命令创建了项目。当我从命令行运行 grails run-app --verbose 时,出现以下异常。

Caching deactivated: failed to create cache directory: C:/grails/2.3.5/
java.lang.NoClassDefFoundError: org/apache/catalina/startup/Tomcat
  at...
Caused by: java.lang.ClassNotFoundException: org.apache.cataliina.startup.Tomcat

下面是我的 BuildConfig.groovy 文件的一部分

...
      dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
        //compile 'xlan:serializer:jar:2.7.1'
        // runtime 'mysql:mysql-connector-java:5.1.27'
        // runtime 'org.postgresql:postgresql:9.3-1100-jdbc41'
        //These were added for mongodb
        compile 'org.grails:grails-datastore-gorm:3.1.0.RELEASE'
        compile 'org.grails:grails-datastore-core:3.1.0.RELEASE'
        test 'org.grails:grails-datastore-simple:3.1.0.RELEASE'
        compile "net.sf.ehcache:ehcache-core:2.4.6"
        compile 'org.grails:grails-async:jar:2.3.8'
        compile 'org.springframework:spring-tx:3.2.8.RELEASE'
    }

    plugins {
        // plugins for the build system only
        //build ":serializer:2.7.1"
        build ':tomcat:7.0.50'
        // plugins for the compile step
        compile ":scaffolding:2.0.1"

        //compile ':cache:1.1.1'
        compile ':mongodb:3.0.1'
        compile ":jquery-ui:1.10.3"

        compile ":spring-security-core:2.0-RC4"
        // plugins needed at runtime but not for compilation
       // runtime ":hibernate:3.6.10.7" // or ":hibernate4:4.1.11.6"
        runtime ":database-migration:1.3.8"
        runtime ":jquery:1.10.2.2"
        runtime ":resources:1.2.1"
        // Uncomment these (or add new ones) to enable additional resources capabilities
        //runtime ":zipped-resources:1.0.1"
        //runtime ":cached-resources:1.1"
        //runtime ":yui-minify-resources:0.1.5"
    }...

我正在运行这个指向本地存储库的 grails 离线模式。只有在我将下面列出的 jars 添加到我的 Groovy/Grails 工具套件文件夹中的 lib 文件夹中之后才能成功编译,以便它们位于类路径中(这修复了 catalina 中的 TomcatKillSwitch 错误)

  1. catalina.jar
  2. catalina-ant.jar
  3. catalina-ha.jar
  4. catalina-tribes.jar
  5. tomcat-api.jar
  6. tomcat-coyote.jar
  7. tomcat-util.jar

为什么grails找不到Tomcat,为什么不能创建缓存?

4

1 回答 1

0

删除那些jar文件;您可能已经“修复”了这个问题,但您实际上只是隐藏了一个症状,问题仍然存在,并且可能会在您下次添加插件时重新出现。继续删除 lib 目录 - 它可能会继续用它的存在来诱惑你。

在我看来,核心问题简单明了;Grails 无法创建C:/grails/2.3.5/. 副作用没有明确说明,其中之一是 Grails 无法正确解压缩 Tomcat 插件(可能还有其他插件)并使用其源代码和 jar 依赖项来增加类路径。

解决此问题的适当方法是升级到合理的操作系统。我建议使用 Linux,其他人在成为一大群志同道合的“个人”中的一员时会感到安慰,并建议使用 OSX,但实际上除了 Windows 之外的任何东西都可以。

我将在这里冒险并声称如果您要承担手动创建的任务,您可以结束这个缓存贫困的黑暗时期c:\grails。默认情况下,您不能在最新版本的 Windows 中的 C: 驱动器的根目录中创建文件或目录;当然这是有可能的,在这个过程中你会被问太多“你确定”之类的问题,但它可以做到。

重新启动后您将拥有丰富的缓存,因为 Grails 将能够创建 2.3.5 目录,解压缩插件,并以编程方式引用以前下载/缓存的 Tomcat jar,而不必将它们放在 lib 目录中。

于 2014-11-14T04:38:20.070 回答