Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h1>Ant Task Troubleshooting</h1> <h3>The Common Problem</h3> <p>Very often, the groovy or groovyc tasks fail with a ClassNotFoundException for the class GroovySourceAst.</p> <h3>The Reason</h3> <p>If it's failing with a ClassNotFoundException for a class other than GroovySourceAst, welcome to Ant. As the Ant manual for <a href="http://ant.apache.org/manual/using.html#external-tasks">external tasks</a> says, " Don't add anything to the CLASSPATH environment variable - this is often the reason for very obscure errors. Use Ant's own mechanisms for adding libraries." And as its <a href="http://ant.apache.org/manual/running.html#libs">library directories</a> section says, "Ant should work perfectly well with an empty CLASSPATH environment variable, something the the -noclasspath option actually enforces. We get many more support calls related to classpath problems (especially quoting problems) than we like." So try running Ant as <code>ant -noclasspath</code>, or even alias ant to that in your shell.</p> <p>If the class that isn't found is GroovySourceAst and the above doesn't help, somewhere you have a conflicting antlr in your classpath. This may be because you are using maven and one of this parts is polluting the classpath or you have a different antlr jar in your classpath somewhere.</p> <h3>Solution 1: groovy-all</h3> <p>Use the groovy-all-VERSION.jar from the groovy distribution and not the normal groovy jar. The groovy-all-VERSION.jar does already contain antlr and asm libs in a seperate namespace so there should be no conflict with other libs around.</p> <h3>Solution 2: using loaderref</h3> <p>Sometimes it's not possible to use the groovy-all-VERSION.jar, for example because you want to build groovy before creating the jar. In this case you have to add a loaderref to the task definition. But that alone will not help. You have to add the rootLoaderRef task to set this loader reference. For example:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <taskdef name="rootLoaderRef" classname="org.codehaus.groovy.ant.RootLoaderRef" classpathref="task.classpath"/> <rootLoaderRef ref="tmp.groovy.groovyc"> <classpath refid="execution.classpath"/> </rootLoaderRef> <rootLoaderRef /> <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" loaderref="tmp.groovy.groovyc"/> </pre></td></tr></table> <p>The groovy task will now be created using the tmp.groovy.groovyc class loader, which tries to avoid loading conflicting jars like antlr. It's important to execute the rootLoaderRef task once before the taskdef using the loaderref defined by the rootLoaderRef.</p> <h3>Solution 3: appropriate classpath set up</h3> <p>You may need to adjust your classpath setup to include the jars you are trying to use. For instance, if you have placed the groovy jar in your Ant LIB folder, then Groovy will be in Ant's root classloader. If you now wish to refer to an external library, e.g. a JDBC driver, you may need to place that library also in your Ant LIB folder so that it is visible in the same classLoader as Groovy. See the loaderref discussion above also.</p> <p>Also, the Groovy distribution doesn't include the entire Ant distribution. If you are using some optional Ant tasks, you may need to add some additional jars to your classpath to use the additional features. Here is an incomplete list of some Ant tasks which require additional jars:</p> <table class="confluenceTable"><tbody> <tr> <th class="confluenceTh"><p> Ant Task </p></th> <th class="confluenceTh"><p> Additional Jar(s) </p></th> </tr> <tr> <td class="confluenceTd"><p> junitreport </p></td> <td class="confluenceTd"><p> ant-trax.jar, xercesImpl.jar, xml-apis.jar </p></td> </tr> <tr> <td class="confluenceTd"><p> mail </p></td> <td class="confluenceTd"><p> mail.jar, activation.jar, smtp.jar (if using SMTP), ant-javamail.jar (if sending MIME email) </p></td> </tr> <tr> <td class="confluenceTd"><p> sql </p></td> <td class="confluenceTd"><p> <em>your_JDBC_driver</em> </p></td> </tr> </tbody></table> <h3>All Solved?</h3> <p>No, both Solutions will not help if you have conflicting ant jars or common-logging jars somewhere. Solution 2 is able to solve much more difficult jar problems as long as your classpath is as clean as possible. if you want to be on the safe side you have to fork the javaVM which means you have to use the task like this:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <!-- lets fork a JVM to avoid classpath hell --> <java classname="org.codehaus.groovy.ant.Groovyc" fork="yes" failonerror="true"> <classpath refid="project.classpath"/> <arg value="${build.classes.dir}"/> <arg value="${src.dir}"/> </java> </pre></td></tr></table> <h3>References</h3> <ul> <li><a class="confluence-link" href="/display/GROOVY/Ant+Integration+with+Groovy" data-linked-resource-id="81156" data-linked-resource-type="page" data-linked-resource-default-alias="Ant Integration with Groovy" data-base-url="http://docs.codehaus.org">Ant Integration with Groovy</a></li> <li><a href="http://ant.apache.org/manual/develop.html">Developing Custom Tasks</a></li> </ul>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced