title: java.lang.OutOfMemoryError: Java heap space on my ant junit task even when I have setted maxmemory="1024m"
body: <p>I am having an issue with my junit task. When I run it from eclipse, it goes well with the -Xmx1000m argument. It was working too in my ant task to but suddenly it stop working, throwing this out of memory exception. I have configured the maxmemory="1024m" on the ant task but with no success.</p>
  
  <p>Here's the stack trace:</p>
  
  <pre><code> [junit] java.lang.IllegalStateException: Failed to load ApplicationContext
      [junit]     at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
      [junit]     at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
      [junit]     at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
      [junit]     at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
      [junit]     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
      [junit]     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
      [junit]     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      [junit]     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
      [junit]     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      [junit]     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
      [junit]     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      [junit]     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      [junit]     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      [junit]     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      [junit]     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      [junit]     at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      [junit]     at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      [junit]     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
      [junit]     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      [junit]     at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:420)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1339)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:831)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1785)
      [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:785)
      [junit]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      [junit]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      [junit]     at java.lang.reflect.Method.invoke(Method.java:597)
      [junit]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
      [junit]     at org.apache.tools.ant.Task.perform(Task.java:348)
      [junit]     at org.apache.tools.ant.Target.execute(Target.java:357)
      [junit]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
      [junit]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
      [junit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
      [junit]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      [junit]     at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
      [junit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
      [junit]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:423)
      [junit]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:137)
      [junit] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'streamingCotizacionesDAO' defined in class path resource [applicationContext-core-Dao.xml]: Cannot resolve reference to bean 'hibernateTemplateSeguro' while setting bean property 'hibernateTemplateSeguro'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplateSeguro' defined in class path resource [applicationContext-dataAccess.xml]: Cannot resolve reference to bean 'sessionFactorySeguro' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactorySeguro' defined in class path resource [applicationContext-dataAccess.xml]: Invocation of init method failed; nested exception is java.lang.OutOfMemoryError: Java heap space
      [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
      [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
      [junit]     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
      [junit]     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
      [junit]     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
      [junit]     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
      [junit]     at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
      [junit]     at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
      [junit]     at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
      [junit]     at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
      [junit]     ... 39 more
      [junit] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplateSeguro' defined in class path resource [applicationContext-dataAccess.xml]: Cannot resolve reference to bean 'sessionFactorySeguro' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactorySeguro' defined in class path resource [applicationContext-dataAccess.xml]: Invocation of init method failed; nested exception is java.lang.OutOfMemoryError: Java heap space
      [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
      [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
      [junit]     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
      [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
      [junit]     ... 55 more
      [junit] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactorySeguro' defined in class path resource [applicationContext-dataAccess.xml]: Invocation of init method failed; nested exception is java.lang.OutOfMemoryError: Java heap space
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
      [junit]     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
      [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
      [junit]     ... 65 more
      [junit] Caused by: java.lang.OutOfMemoryError: Java heap space
      [junit]     at java.util.Arrays.copyOf(Arrays.java:2882)
      [junit]     at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
      [junit]     at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390)
      [junit]     at java.lang.StringBuffer.append(StringBuffer.java:224)
      [junit]     at org.hibernate.sql.Select.toStatementString(Select.java:68)
      [junit]     at org.hibernate.loader.collection.BasicCollectionJoinWalker.initStatementString(BasicCollectionJoinWalker.java:128)
      [junit]     at org.hibernate.loader.collection.BasicCollectionJoinWalker.&lt;init&gt;(BasicCollectionJoinWalker.java:62)
      [junit]     at org.hibernate.loader.collection.BasicCollectionLoader.&lt;init&gt;(BasicCollectionLoader.java:53)
      [junit]     at org.hibernate.loader.collection.BasicCollectionLoader.&lt;init&gt;(BasicCollectionLoader.java:40)
      [junit]     at org.hibernate.loader.collection.BasicCollectionLoader.&lt;init&gt;(BasicCollectionLoader.java:31)
      [junit]     at org.hibernate.loader.collection.BatchingCollectionInitializer.createBatchingCollectionInitializer(BatchingCollectionInitializer.java:92)
      [junit]     at org.hibernate.persister.collection.BasicCollectionPersister.createCollectionInitializer(BasicCollectionPersister.java:297)
      [junit]     at org.hibernate.persister.collection.AbstractCollectionPersister.postInstantiate(AbstractCollectionPersister.java:541)
      [junit]     at org.hibernate.impl.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:294)
      [junit]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
      [junit]     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
      [junit]     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
      [junit]     at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$5.run(AbstractAutowireCapableBeanFactory.java:1467)
      [junit]     at java.security.AccessController.doPrivileged(Native Method)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1465)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
      [junit]     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
      [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
      [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
      [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
      [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
  </code></pre>