title: How to specify JAR dependencies in Grails BuildConfig.groovy?
body: <p>I am getting the following error when trying to deploy a WAR file (MIPS.war) onto a target environment:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Saw a post on the web (<a href="http://jira.codehaus.org/browse/GRAILS-6057" rel="nofollow noreferrer">http://jira.codehaus.org/browse/GRAILS-6057</a>) which says that classes/JAR needs to be added to the test or run class path. <strong>Question</strong>: where is this specified? Also, do I need to specify the dependencies in Grails config file (BuildConfig.groovy) under the 'dependencies' section? How are these specified for a jar e.g. a jar I have under the /lib folder is 'ant-1.6.5.jar'? </p>
  
  <pre><code>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'
  }
  </code></pre>
  
  <p>}</p>