I have an relatively old Grails app that uses ant to build the application. In the test server it build without any problems, but when I try to run it on my PC, I get a consistent error:
Caused by: jar:file:/C:/ant/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Problem: failed to create task or type componentdef
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
at org.apache.tools.ant.UnknownElement.getNotFoundException(UnknownElement.java:484)
at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:416)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
at org.apache.tools.ant.taskdefs.Antlib.execute(Antlib.java:146)
at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:432)
... 63 more
I have found that the error happens in the following part of the build:
<macrodef name="grails">
<attribute name="script"/>
<attribute name="args" default="" />
<sequential>
<grailsTask script="#{script}" args="#{args}" classpathref="grails.classpath">
<compileClasspath refid="compile.classpath"/>
<testClasspath refid="test.classpath"/>
<runtimeClasspath refid="app.classpath"/>
</grailsTask>
</sequential>
</macrodef>
If I comment out , there are no more errors.
For further refererence, here's the whole error dump:
G:\chp\src\hewittportlet\build.xml:131: The following error occurred while executing this line:
G:\chp\src\hewittportlet\build.xml:53: Unable to start Grails: java.lang.reflect.InvocationTargetExc
eption
at grails.ant.GrailsTask.runGrails(GrailsTask.java:124)
at grails.ant.GrailsTask.execute(GrailsTask.java:78)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1360)
at org.apache.tools.ant.Project.executeTarget(Project.java:1329)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1212)
at org.apache.tools.ant.Main.runBuild(Main.java:801)
at org.apache.tools.ant.Main.startAnt(Main.java:218)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.codehaus.groovy.grails.cli.support.GrailsBuildHelper.execute(GrailsBuildHelper.java:9
4)
at grails.ant.GrailsTask.runGrails(GrailsTask.java:113)
... 31 more
Caused by: java.lang.reflect.InvocationTargetException
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.codehaus.groovy.grails.cli.support.GrailsBuildHelper.execute(GrailsBuildHelper.java:8
8)
... 32 more
Caused by: The following error occurred while executing this line:
jar:file:/C:/ant/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Problem: failed t
o create task or type componentdef
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:508)
at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:434)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:281)
at org.apache.tools.ant.ComponentHelper.checkNamespace(ComponentHelper.java:790)
at org.apache.tools.ant.ComponentHelper.getDefinition(ComponentHelper.java:260)
at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:237)
at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:216)
at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:414)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:186)
at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:147)
at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:154)
at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64)
at org.codehaus.gant.GantBuilder.invokeMethod(GantBuilder.java:89)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.codehaus.gant.GantBinding.initializeGantBinding(GantBinding.groovy:109)
at org.codehaus.gant.GantBinding.this$4$initializeGantBinding(GantBinding.groovy)
at org.codehaus.gant.GantBinding$this$4$initializeGantBinding.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:
44)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:1
43)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:1
47)
at org.codehaus.gant.GantBinding.<init>(GantBinding.groovy:42)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.callPluginOrGrailsScript(GrailsScriptRu
nner.java:355)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:
279)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:
205)
... 37 more
Caused by: jar:file:/C:/ant/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Proble
m: failed to create task or type componentdef
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
at org.apache.tools.ant.UnknownElement.getNotFoundException(UnknownElement.java:484)
at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:416)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
at org.apache.tools.ant.taskdefs.Antlib.execute(Antlib.java:146)
at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:432)
... 63 more
Total time: 34 seconds
Grails isn't compatible with Ant 1.8 - you need to use 1.7.x.
I found the source of the problem.
The problem was not the version of Ant, but rather the version of Grails and missing scripts. This application was using a deprecated version of Grails (version 1.1.1).
The following code, which I'm re-listing for everybody's conveniences, is invoking a script. However, in this particular application, the script had been removed, which caused Grails' build process to crash:
<macrodef name="grails">
<attribute name="script"/>
<attribute name="args" default="" />
<sequential>
<grailsTask script="#{script}" args="#{args}" classpathref="grails.classpath">
<compileClasspath refid="compile.classpath"/>
<testClasspath refid="test.classpath"/>
<runtimeClasspath refid="app.classpath"/>
</grailsTask>
</sequential>
</macrodef>
The solution was simple: to upgrade Grails to a more recent version, such as 1.3.5. The build worked without problems after that, even though some scripts were missing.
I would speculate that this new behavior allowed to generate scripts during the scaffolding, but at the same time give the freedom to the developer to remove unwanted or unnecessary scripts.
Thanks to Burth Beckwith for his insights.
Luis Colorado
Related
I have the following ant target:
<path id="test-classpath">
<fileset dir="lib">
<include name="*.jar" />
</fileset>
<pathelement path="bin/release" />
</path>
<target name="run-test">
<junit printsummary="yes" haltonfailure="yes" fork="true">
<formatter type="failure"/>
<test name="someNamespace.someTest" />
<classpath refid="test-classpath" />
</junit>
</target>
When I try to run it from the command-line, I am getting the following output:
>ant run-test
Buildfile: ...\build.xml
[echo] 2016-03-30 20:29:29
run-test:
[junit] Exception in thread "main" java.lang.reflect.InvocationTargetException
[junit] at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:343)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:257)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.transferFormatters(JUnitTestRunner.java:1085)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1180)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1033)
[junit] Caused by: java.lang.reflect.InvocationTargetException
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at java.lang.reflect.Method.invoke(Method.java:498)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:337)
[junit] ... 4 more
[junit] Caused by: java.lang.NullPointerException
[junit] at org.apache.tools.ant.taskdefs.optional.junit.FailureRecorder.setProject(FailureRecorder.java:153)
[junit] ... 9 more
BUILD FAILED
...\build.xml:171: Using loader AntClassLoader[
C:\Program Files (x86)\apache-ant-1.9.6\lib\ant-launcher.jar;
C:\Program Files (x86)\apache-ant-1.9.6\lib\ant.jar;
C:\Program Files (x86)\apache-ant-1.9.6\lib\ant-junit.jar;
C:\Program Files (x86)\apache-ant-1.9.6\lib\ant-junit4.jar;
...\lib\commons-math3-3.5.jar;
...\lib\hamcrest-core-1.3.jar;
...\lib\junit-4.11.jar;
...\lib\log4j-api-2.5.jar;
...\lib\log4j-core-2.5.jar;
...\bin\release] on class org.apache.tools.ant.taskdefs.optional.junit.FailureRecorder:
java.lang.NoClassDefFoundError: junit/framework/TestListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1407)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1085)
at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:58)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:287)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmExit(JUnitTask.java:1854)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmCrash(JUnitTask.java:1818)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1295)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:1024)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:2105)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:832)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:853)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
Caused by: java.lang.ClassNotFoundException: junit.framework.TestListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 51 more
Total time: 3 seconds
The test runs successfully within Eclipse Mars (4.5.2). Does anyone know why this would be happening, and how I can get my JUnit test to run through ant? I am using JUnit 4.11, and have tried ant v1.9.3 and v1.9.6 (the above output was generated from ant v1.9.6).
EDIT
I also tested using ant v1.8.4, per the recommendations in the comments, but that doesn't have any effect on the resulting crash (other than the version numbers of the jar files).
According to this question - Class not found with Ant, Ivy and JUnit - error in build.xml? - there is a bug in ant 1.9+ and you should try ant 1.8.4.
I finally figured out what the problem was. My JUnit task classpath was incorrect, as I forgot to include the location of my test suite class. Once I corrected the classpath, everything worked as expected. Still, I feel that this is a bug that should be addressed by either the Ant or JUnit teams. A message such as, "Class XXX could not be loaded" would have been much more helpful.
I tried to execute below mentioned ant mail task, I'm getting error message: java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage.
I have created environment variable for ant.
Also placed mail.jar, activation jar & ant-javamail jar in lib folder as well as in eclipse -> preferences -> Global Entries. Anything else required for executing ant mail task? Please suggest.
<target description="Generates and send TestNG test reports" name="send-report">
<mail mailhost="smtp.sears.com" mailport="25" user="kmart\vlakshm" password="AK230211$$" ssl="true" subject="Test build">
<from address="vijayalakshmi.lakshmanan#searshc.com"></from>
<replyto address="vijayalakshmi.lakshmanan#searshc.com"></replyto>
<to address="vijayalakshmi.lakshmanan#searshc.com"></to>
<message>Please find the attached report for Sears International smoke test results.</message>
<attachments>
<fileset dir="C:\\Documents and Settings\\vlakshm\\workspace\\INTL_REG\\test-output\\emailable-report.html">
<include name="**/*.zip"/>
</fileset>
</attachments>
</mail>
</target>
In command prompt,executed below mentioned command
ant send-report
Getting below mentioned exception
build.xml:70: java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.tools.ant.taskdefs.email.EmailTask.execute(EmailTask.java:
452)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 0 seconds
add mail.jar and activation.jar in ANT_HOME/lib or use both jar form your project/lib
My Ant 1.8.2 build started failing with HTTP 303 responses from the W3C web site in response to requests for SVG DTDs. So I'm trying to introduce an XML Catalog to resolve them locally.
If I make no changes to the classpath, I get:
Warning: XML resolver not found; external catalogs will be ignored
If I add resolver.jar from Apache XML Commons 1.2 to the classpath (e.g. by using -lib on the ant invocation), I get
/Users/mike/..../build.xml:123: java.lang.reflect.InvocationTargetException
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.tools.ant.types.XMLCatalog$ExternalResolver.processExternalCatalogs(XMLCatalog.java:1115)
at org.apache.tools.ant.types.XMLCatalog$ExternalResolver.resolveEntity(XMLCatalog.java:960)
at org.apache.tools.ant.types.XMLCatalog.resolveEntity(XMLCatalog.java:391)
which suggests to me that the resolver.jar I am using has been located, but doesn't have the interface that Ant is expecting.
Where should I get the correct resolver.jar to use with Ant?
I found the solution (well, a workaround...)
The InvocationTargetException turned out to be a red herring - a secondary error. The primary error was as follows: my catalog file catalog.xml contained a relative reference to a DTD catalog.dtd, and Ant (or the resolver) was failing to resolve the reference to catalog.dtd. It was looking in the directory containing my build file, not the directory containing the catalog. This is clearly a bug somewhere; my suspicion, if I were investigating further, would be that Ant is passing the catalog file to the catalog resolver with no base URI, or with an incorrect base URI, so the XML parser has to guess where to find the DTD, and guesses wrong.
My solution was to remove the reference to the DTD. After this, URIs listed in the catalog were correctly resolved to local copies. Interestingly, the references to local copies are also relative to the catalog, so it seems that the catalog resolver knows where the catalog is, but someone isn't telling Xerces at the time it is parsed.
I had the same issue, but for me, the upgrading from Ant 1.8.1 to 1.9.4 solved the problem.
My guess is that the root cause is bug 52754.
EDIT: The same issue resurfaced in a slightly different form, using JDK 1.6.0_18, with a stack trace like this:
java.lang.reflect.InvocationTargetException
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.tools.ant.types.XMLCatalog$ExternalResolver.processExternalCatalogs(XMLCatalog.java:1116)
at org.apache.tools.ant.types.XMLCatalog$ExternalResolver.resolve(XMLCatalog.java:1007)
at org.apache.tools.ant.types.XMLCatalog.resolve(XMLCatalog.java:420)
at net.sf.saxon.style.XSLGeneralIncorporate.getIncludedStylesheet(XSLGeneralIncorporate.java:104)
at net.sf.saxon.style.XSLStylesheet.spliceIncludes(XSLStylesheet.java:754)
at net.sf.saxon.style.XSLStylesheet.preprocess(XSLStylesheet.java:676)
at net.sf.saxon.PreparedStylesheet.setStylesheetDocument(PreparedStylesheet.java:331)
at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:163)
at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:139)
at org.apache.tools.ant.taskdefs.optional.TraXLiaison.readTemplates(TraXLiaison.java:300)
at org.apache.tools.ant.taskdefs.optional.TraXLiaison.createTransformer(TraXLiaison.java:317)
at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:178)
at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:842)
at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:432)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1937)
at java.lang.String.substring(String.java:1904)
at org.apache.xml.resolver.helpers.PublicId.normalize(Unknown Source)
at org.apache.xml.resolver.Catalog.addEntry(Unknown Source)
at org.apache.tools.ant.types.resolver.ApacheCatalog.addEntry(ApacheCatalog.java:118)
at org.apache.xml.resolver.readers.OASISXMLCatalogReader.startElement(Unknown Source)
at org.apache.xml.resolver.readers.SAXCatalogReader.startElement(Unknown Source)
at org.apache.xml.resolver.readers.SAXParserHandler.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.apache.xml.resolver.readers.SAXCatalogReader.readCatalog(Unknown Source)
at org.apache.xml.resolver.Catalog.parseCatalogFile(Unknown Source)
at org.apache.xml.resolver.Catalog.parsePendingCatalogs(Unknown Source)
at org.apache.xml.resolver.Catalog.parseCatalog(Unknown Source)
at org.apache.tools.ant.types.resolver.ApacheCatalogResolver.parseCatalog(ApacheCatalogResolver.java:118)
... 47 more
Interestingly, the error only occurred on Windows and only sporadically, maybe one time out of seven or so.
The error originates in the normalize function of the PublicId class in the Apache Resolver library.
normal.indexOf(" ") would sometimes return the wrong value. For example, if the input string was -//OASIS//ELEMENTS DITA 1.x Programming Domain//EN, the pos variable would get 50 as its value, even though the public ID string has no extra spaces whatsoever.
That leads me to think that the root cause might be somehow related to JDK bug #6967156, but I can't be sure at all, since in our case, the error was intermittent, but nothing in the bug report suggests that.
I am using GGST 3.1 with a Grails 1.3.7 app. I created a unit test for a service method, and ran it successfully. (And it passed, too!) I then modified the method under test, modified the unit test, and tried to run it again. The test failed to run with the following stack trace
java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/BytecodeInterface8
at com.fxpal.querium.QuerySpecService.extractQueryFields(QuerySpecService.groovy:133)
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.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:63)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at com.fxpal.querium.QuerySpecServiceTests.testExtractQuery(QuerySpecServiceTests.groovy:18)
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 junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.BytecodeInterface8
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 30 more
This seems similar to other instances of this error I've seen related to deploying WAR files, but in my case, I was just running a unit test through the IDE. (Not grails test-app but by selecting Run as/JUnit test from the context menu.)
What should I be trying next?
I believe this error is because (both in the war and our case) there are two groovy versions (console and IDE), trying to run the same test cases, and sometimes they are taking each others bytecode. One thing to make sure is if they are not sharing the folder where the bytecode is saved.
Something else you can try is to verify the groovy libraries are in the test's classpath, last time this happened to me, I just added them to the classpath and it run normally.
Ger
Below two stacks from the initial JVM and forked JVM seems saying the test code executed twice instead of only one time. I wonder why it is not only executed in the forked one.
JUnit test config: fork=true, forkmode=perTest
at oracle.security.jps.internal.policystore.PolicyUtil.getPDPService(PolicyUtil.java:3099)
at oracle.security.jps.internal.policystore.PolicyDelegationController.<init>(PolicyDelegationController.java:164)
at oracle.security.jps.internal.policystore.JavaPolicyProvider.<init>(JavaPolicyProvider.java:369)
at oracle.security.jps.service.policystore.PolicyStoreTestCaseBase.<init>(PolicyStoreTestCaseBase.java:39)
at oracle.security.jps.service.policystore.JpsJavaPolicyPreTestCase.<init>(JpsJavaPolicyPreTestCase.java:145)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at junit.framework.TestSuite.createTest(TestSuite.java:65)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:283)
at junit.framework.TestSuite.<init>(TestSuite.java:146)
at oracle.security.jps.service.policystore.JpsJavaPolicyPreTestCase.suite(JpsJavaPolicyPreTestCase.java:603)
at devtest.JpsUnitPreTestSuite.suite(JpsUnitPreTestSuite.java:66)
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.testlogic.testrunner.ant.junit4.JUnitTestRunner.createTestSuite(JUnitTestRunner.java:929)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.createTestSuite(TLJUnitTestRunner.java:217)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.run(JUnitTestRunner.java:366)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.run(TLJUnitTestRunner.java:111)
at org.testlogic.testrunner.ant.junit4.JUnitTask.runTestInVM(JUnitTask.java:1319)
at org.testlogic.testrunner.ant.junit4.TLJUnitTask.runInitMode(TLJUnitTask.java:327)
at org.testlogic.testrunner.ant.junit4.TLJUnitTask.run(TLJUnitTask.java:120)
at org.testlogic.impl.ant.JITInitModeListener.runTestTaskInInitMode(JITInitModeListener.java:91)
at org.testlogic.impl.ant.JITInitModeListener.taskStarted(JITInitModeListener.java:121)
at org.apache.tools.ant.Project.fireTaskStarted(Project.java:2131)
at org.apache.tools.ant.Task.perform(Task.java:345)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1307)
at org.testlogic.impl.ant.AntTaskUtils.simulateAntCall(AntTaskUtils.java:273)
at org.testlogic.impl.ant.executionPlan.model.CommandRunnable.runCommand(CommandRunnable.java:178)
at org.testlogic.impl.ant.executionPlan.model.CommandRunnable.run(CommandRunnable.java:105)
at java.lang.Thread.run(Thread.java:662)
and
at oracle.security.jps.internal.policystore.PolicyUtil.getPDPService(PolicyUtil.java:3099)
at oracle.security.jps.internal.policystore.PolicyDelegationController.<init>(PolicyDelegationController.java:164)
at oracle.security.jps.internal.policystore.JavaPolicyProvider.<init>(JavaPolicyProvider.java:369)
at oracle.security.jps.service.policystore.PolicyStoreTestCaseBase.<init>(PolicyStoreTestCaseBase.java:39)
at oracle.security.jps.service.policystore.JpsJavaPolicyPreTestCase.<init>(JpsJavaPolicyPreTestCase.java:145)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at junit.framework.TestSuite.createTest(TestSuite.java:65)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:283)
at junit.framework.TestSuite.<init>(TestSuite.java:146)
at oracle.security.jps.service.policystore.JpsJavaPolicyPreTestCase.suite(JpsJavaPolicyPreTestCase.java:603)
at devtest.JpsUnitPreTestSuite.suite(JpsUnitPreTestSuite.java:66)
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.testlogic.testrunner.ant.junit4.JUnitTestRunner.createTestSuite(JUnitTestRunner.java:929)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.createTestSuite(TLJUnitTestRunner.java:217)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.run(JUnitTestRunner.java:366)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.run(TLJUnitTestRunner.java:111)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.launch(JUnitTestRunner.java:869)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.main(JUnitTestRunner.java:714)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.main(TLJUnitTestRunner.java:209)
JUnit section in build.xml
<!-- Run in its own JVM. todir="${test.results.dir}" -->
<test todir="${test.results.dir}" name="devtest.JpsUnitPreTestSuite" unless="jps.testcase"/>
<!-- Followed by these tests. -->
<test todir="${test.results.dir}" name="devtest.JpsUnitTestSuite" unless="jps.testcase"/>
<!-- JVM system properties -->
<sysproperty key="src.home" value="${env.ADE_VIEW_ROOT}"/>
<sysproperty key="ant.home" value="${ant.home}"/>
...