History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-894
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Peter Kelley
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

Exception generating template using ant task

Created: 17/Jun/05 01:04 AM   Updated: 19/Jun/05 08:22 PM
Component/s: None
Affects Version/s: 1.0-JSR-2
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive template.zip (1.37 Mb)

Environment:
Apache Ant version 1.6.5 compiled on June 2 2005
java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)

Testcase included: yes


 Description  « Hide
When I run the following script (also attached below) from the command prompt it works:

import groovy.text.Template
import groovy.text.SimpleTemplateEngine
import groovy.lang.Script
tmplt = "\${favlang} is my favorite language"
binding = ["favlang": "Groovy"]
engine = new SimpleTemplateEngine()
output = engine.createTemplate(tmplt).make(binding)
println output.toString()

When I run it from ant it fails with the message shown below. By commenting out lines I have determined that the problem is on line 7 where the template is bound. I have included a full ant debug trace and the ant build.xml in the attachment.

Buildfile: build.xml

groovy:
[groovy] java.lang.ClassNotFoundException: groovy.lang.Script
[groovy] at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:536)
[groovy] at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
[groovy] at org.codehaus.groovy.classgen.JSRVariableScopeCodeVisitor.addVarNames(JSRVariableScopeCodeVisitor.java
:718)
[groovy] at org.codehaus.groovy.classgen.JSRVariableScopeCodeVisitor.visitClass(JSRVariableScopeCodeVisitor.java:
592)
[groovy] at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:601)
[groovy] at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:848)
[groovy] at org.codehaus.groovy.control.CompilationUnit.classgen(CompilationUnit.java:564)
[groovy] at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:469)
[groovy] at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:246)
[groovy] at groovy.lang.GroovyShell.parseClass(GroovyShell.java:530)
[groovy] at groovy.lang.GroovyShell.parse(GroovyShell.java:542)
[groovy] at groovy.lang.GroovyShell.parse(GroovyShell.java:521)
[groovy] at groovy.lang.GroovyShell.parse(GroovyShell.java:560)
[groovy] at groovy.text.SimpleTemplateEngine.createTemplate(SimpleTemplateEngine.java:68)
[groovy] at groovy.text.TemplateEngine.createTemplate(TemplateEngine.java:56)
[groovy] at gjdk.groovy.text.SimpleTemplateEngine_GroovyReflector.invoke(Unknown Source)
[groovy] at groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
[groovy] at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1386)
[groovy] at groovy.lang.MetaClass.invokeMethod(MetaClass.java:309)
[groovy] at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:145)
[groovy] at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
[groovy] at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
[groovy] at Script1.run(Unknown Source)
[groovy] at org.codehaus.groovy.ant.Groovy.execGroovy(Groovy.java:425)
[groovy] at org.codehaus.groovy.ant.Groovy.execute(Groovy.java:327)
[groovy] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[groovy] at org.apache.tools.ant.Task.perform(Task.java:364)
[groovy] at org.apache.tools.ant.Target.execute(Target.java:341)
[groovy] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[groovy] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
[groovy] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
[groovy] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
[groovy] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
[groovy] at org.apache.tools.ant.Main.runBuild(Main.java:668)
[groovy] at org.apache.tools.ant.Main.startAnt(Main.java:187)
[groovy] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
[groovy] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)

BUILD FAILED
java.lang.NoClassDefFoundError: groovy/lang/Script

Total time: 4 seconds

The full debug trace is included with the example files as output.txt



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Jeremy Rayner - 17/Jun/05 04:29 AM
I suspect a classloader issue, as Ant works in a different context to usual...

Guillaume Laforge - 18/Jun/05 07:16 AM
Where is your groovy-all-xxx.jar? is it in ANT_HOME/lib ? or just un your project lib directory?
I think groovy's jar needs to be in the lib directory of your Ant installation.

Peter Kelley - 19/Jun/05 08:21 PM
OK, that appears to work. it's funny that the script gets to that point before falling over. Something to do with template instantiation.

Peter Kelley - 19/Jun/05 08:22 PM
Was a problem with jars in the classpath