4

尝试将 WAR 文件 (MIPS.war) 部署到目标环境时出现以下错误:

INFO: Deploying web application archive MIPS.war
2010-08-04 12:44:56,977 [main] ERROR context.ContextLoader  - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/persistence/Entity
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1401)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:540)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
        at org.codehaus.groovy.grails.web.context.GrailsContextLoader.createWebApplicationContext(GrailsContextLoader.java:66)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:192)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:830)
        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:719)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.NoClassDefFoundError: javax/persistence/Entity
        at org.codehaus.groovy.grails.commons.AnnotationDomainClassArtefactHandler.isJPADomainClass(AnnotationDomainClassArtefactHandler.java:47)
        at org.codehaus.groovy.grails.commons.AnnotationDomainClassArtefactHandler.isArtefactClass(AnnotationDomainClassArtefactHandler.java:39)
        at org.codehaus.groovy.grails.commons.ArtefactHandlerAdapter.isArtefact(ArtefactHandlerAdapter.java:64)
        at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.configureLoadedClasses(DefaultGrailsApplication.java:331)
        at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.initialise(DefaultGrailsApplication.java:835)
        at org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean.afterPropertiesSet(GrailsPluginManagerFactoryBean.java:119)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
        ... 37 more
Caused by: java.lang.ClassNotFoundException: javax.persistence.Entity
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
        ... 45 more
04-Aug-2010 12:44:56 org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
04-Aug-2010 12:44:56 org.apache.catalina.core.StandardContext start
SEVERE: Context [/MIPS] startup failed due to previous errors

在网上看到一篇文章(http://jira.codehaus.org/browse/GRAILS-6057),上面说需要将类/JAR 添加到测试或运行类路径中。问题:这是在哪里指定的?另外,我是否需要在“依赖项”部分下的 Grails 配置文件 (BuildConfig.groovy) 中指定依赖项?如何为 jar 指定这些,例如 /lib 文件夹下的 jar 是“ant-1.6.5.jar”?

grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits( "global" ) {
    // uncomment to disable ehcache
    // excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {        
    grailsPlugins()
    grailsHome()

    // uncomment the below to enable remote dependency resolution
    // from public Maven repositories
    mavenLocal()

    //mavenCentral()
    //mavenRepo "http://snapshots.repository.codehaus.org"
    //mavenRepo "http://repository.codehaus.org"
    //mavenRepo "http://download.java.net/maven/2/"
    //mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

    runtime 'net.sf.json-lib:json-lib:2.3.jdk15'
}

}

4

2 回答 2

3

您可以像这样指定一个平面目录和一个特定的 jar 文件


repositories { 
        grailsPlugins() 
        grailsHome() 
        grailsCentral() 

        // uncomment the below to enable remote dependency resolution 
        // from public Maven repositories 
        mavenLocal() 
        mavenCentral() 

        // Hardcoded path to the jar fiels
        flatDir name:'myRepo', dirs:'/${PATH}/lib' 

    } 
    dependencies { 
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg. 
        specify the jar file here
        compile 'org.neo4j:${YOUR_JAR_NAME}:1.4.1' 


    }

于 2011-08-05T07:42:08.217 回答
3

看看 Graeme 的回复。您应该能够添加:

grails.war.dependencies = ["whatever.jar"]

到您的 Config.groovy。

于 2010-08-04T17:29:26.507 回答