Hi Russel. Thanks for your answers.
I think the problem is the "classpath" closure defined somewhere in
Grails. Try this in your pure Gant script:
import org.codehaus.gant.GantState
target(main: "The description of the script goes here!") {
classpath = {}
def dir = new File('Material')
GantState.verbosity = GantState.VERBOSE
ant.logger.setMessageOutputLevel(GantState.verbosity)
ant.java(classname: 'def.Def', fork: true, dir: dir) {
classpath {
pathelement(location: "${dir}/def.jar")
}
}
}
setDefaultTarget(main)
You will probably get:
[java] Executing '/usr/local/jdk1.6.0_23/jre/bin/java' with arguments:
[java] 'def.Def'
[java]
[java] The ' characters around the executable and arguments are
[java] not part of the command.
[java] Exception in thread "main" java.lang.NoClassDefFoundError:
def/Def
[java] Caused by: java.lang.ClassNotFoundException: def.Def
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[java] at java.security.AccessController.doPrivileged(Native
Method)
[java] at
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[java] at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[java] Could not find the main class: def.Def. Program will exit.
[java] Java Result: 1
If I set the classpath to null (in the Gant script inside my Grails
project), before calling ant.java, everything works fine.
Thanks in advance.
Best regards,
Daniel.
Russel Winder wrote:
> Daniel,
>
> I am not totally sure how to quickly construct a small example of a Gant
> script that exhibits the problem behaviour you are finding. I have not
> seen an example of a nested classpath failing in a Gant script, so my
> initial hypothesis is that the problem is not with Gant per se.
>
> Basically, If I create
>
> +build.gant
> +Material
> | + def.jar
>
> and extract the build script to be:
>
> import org.codehaus.gant.GantState
> target(main: "The description of the script goes here!") {
> def dir = new File('Material')
> GantState.verbosity = GantState.VERBOSE
> ant.logger.setMessageOutputLevel(GantState.verbosity)
> ant.java(classname: 'def.Def', fork: true, dir: dir) {
> classpath {
> pathelement(location: "${dir}/def.jar")
> }
> }
> }
> setDefaultTarget(main)
>
> Then I get:
>
> > gant
> main:
> [java] Executing '/usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java' with arguments:
> [java] '-classpath'
> [java] '/home/users/russel/Progs/OddsByLanguage/Gant/DanielHenriqueAlvesLima_2011-08-11/Material/def.jar'
> [java] 'def.Def'
> [java]
> [java] The ' characters around the executable and arguments are
> [java] not part of the command.
> [java] def
> ------ main
>
> BUILD SUCCESSFUL
> Total time: 1.80 seconds
>
>
>
>
> On Wed, 2011-08-10 at 18:44 -0300, Daniel Henrique Alves Lima wrote:
>
>> Hi.
>>
>> I've written a comment about this newbie mistake/gotcha (???):
>>
http://techdm.com/grails/?p=585&lang=en (item 3)
>> Now I'm trying to understand if this is a bug or a limitation and
>> who I should blame: Gant, Grails or myself (for my lack of knowledge) :-)
>>
>> // TestJava.groovy
>> println 'classpath ' + classpath
>> // (...)
>> //ant.path(id: 'defClasspath', { pathelement(location:
>> "${dir}/def.jar" )})
>>
>> ant.java(classname: 'def.Def', fork: true, dir: dir/*,
>> classpathref:'defClasspath'*/) {
>> classpath {
>> pathelement(location: "${dir}/def.jar")
>> }
>> }
>>
>> classpath seems a closure (println is outputing "classpath
>> org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16@5baa8241")
>> So I can write anything inside the nested classpath and ant.java
>> task just fails because def.jar was not added to the classpath.
>>
>> Of course, If i use classpathref instead, everything works as
>> expected. It also works using ant.classpath or ant.java(classpath: ).
>>
>>
http://ant.apache.org/manual/Tasks/java.html>>
>> Thanks in advance.
>>
>> Best regards,
>>
>> Daniel.
>>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email