问题描述
我有一个相对较旧的 Grails 应用程序,它使用 ant 来构建应用程序.在测试服务器中它构建没有任何问题,但是当我尝试在我的 PC 上运行它时,我得到一个一致的错误:
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
推荐答案
我找到了问题的根源.
问题不是 Ant 的版本,而是 Grails 的版本和缺少的脚本.此应用程序使用的是已弃用的 Grails 版本(版本 1.1.1).
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).
为了大家的方便,我重新列出了下面的代码,它正在调用一个脚本.但是,在这个特定的应用程序中,脚本已被删除,导致 Grails 的构建过程崩溃:
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>
解决方案很简单:将 Grails 升级到更新的版本,例如 1.3.5.之后构建工作没有问题,即使缺少一些脚本.
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.
感谢 Burth Beckwith 的见解.
Thanks to Burth Beckwith for his insights.
路易斯科罗拉多
这篇关于ant的componentdef错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!