You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Hunter Peress <hu...@gmail.com> on 2007/11/20 02:36:08 UTC

classpath order wierdness

*First the build file:
*
<?xml version="1.0" encoding="UTF-8" ?>
<project default="go" basedir=".">
        <path id="abc">
                        <pathelement location="resources/bsf-2.4.0.jar"/>
                        <pathelement location="resources/commons-logging.jar
"/>
                        <pathelement location="resources/groovy-all-1.0.jar
"/>
        </path>
  <target name="go">
          <script language="groovy" classpathref="abc">
      println "HELLO"
    </script>
  </target>
</project>

--------------------------------------------------------------------------------
*
Next we run it and watch it error:*
$ ant
Buildfile: build.xml

go:

BUILD FAILED
c:\Documents and Settings\hperess\build.xml:10:
java.lang.NoClassDefFoundError: org/apache/bsf/BSFException

Total time: 0 seconds

--------------------------------------------------------------------------------
*Finally, we run it but including the jars at call time.

*hperess@745-003 ~
$ ant -lib resources/
Buildfile: build.xml

go:
   [script] HELLO

BUILD SUCCESSFUL
Total time: 0 seconds

--------------------------------------------------------------------------------
*Version info:*
hperess@745-003 ~
$ ant -version
Apache Ant version 1.7.0 compiled on December 13 2006

java version 1.6
--------------------------------------------------------------------------------
*
QUESTION:
*
How can I run it so that I don't have to explicitely call ant with -lib??

Re: classpath order wierdness

Posted by Peter Reilly <pe...@gmail.com>.
On Nov 20, 2007 1:36 AM, Hunter Peress <hu...@gmail.com> wrote:
> *First the build file:
> *
> <?xml version="1.0" encoding="UTF-8" ?>
> <project default="go" basedir=".">
>         <path id="abc">
>                         <pathelement location="resources/bsf-2.4.0.jar"/>
>                         <pathelement location="resources/commons-logging.jar
> "/>
>                         <pathelement location="resources/groovy-all-1.0.jar
> "/>
>         </path>
>   <target name="go">
>           <script language="groovy" classpathref="abc">
>       println "HELLO"
>     </script>
>   </target>
> </project>
>
> --------------------------------------------------------------------------------
> *
> Next we run it and watch it error:*
> $ ant
> Buildfile: build.xml
>
> go:
>
> BUILD FAILED
> c:\Documents and Settings\hperess\build.xml:10:
> java.lang.NoClassDefFoundError: org/apache/bsf/BSFException
>
> Total time: 0 seconds
>
> --------------------------------------------------------------------------------
> *Finally, we run it but including the jars at call time.
>
> *hperess@745-003 ~
> $ ant -lib resources/
> Buildfile: build.xml
>
> go:
>    [script] HELLO
>
> BUILD SUCCESSFUL
> Total time: 0 seconds
>
> --------------------------------------------------------------------------------
> *Version info:*
> hperess@745-003 ~
> $ ant -version
> Apache Ant version 1.7.0 compiled on December 13 2006
>
> java version 1.6
> --------------------------------------------------------------------------------
> *
> QUESTION:
> *
> How can I run it so that I don't have to explicitely call ant with -lib??

This is due to classloader delegation issues - see the manual entry for
the script task. This particular use case should work in ant 1.7.1.

With ant 1.7.0 and java6 one can the javax.script interface.
download the groovy-engine from https://scripting.dev.java.net/

    <path id="groovy.path">
      <fileset dir="${user.home}/apps/groovy-1.0/embeddable"
               includes="*.jar"/>
      <fileset dir="${user.home}/apps/jsr223-engines/groovy/build"
               includes="*.jar"/>
    </path>

    <script language="groovy" classpathref="groovy.path"
            manager="javax">
      System.out.println("Hello world")
    </script>

Please note that using a classpathref like this causes a new classloader
to be created for each <script> usage.

Peter
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: classpath order wierdness

Posted by Rainer Noack <ra...@noacks.net>.
Take a look at http://enitsys.sourceforge.net/ant-classloadertask/

Cheers

Rainer Noack 

-----Ursprüngliche Nachricht-----
Von: Hunter Peress [mailto:hunterp@gmail.com] 
Gesendet: Dienstag, 20. November 2007 02:36
An: Ant Users List
Betreff: classpath order wierdness

*First the build file:
*
<?xml version="1.0" encoding="UTF-8" ?>
<project default="go" basedir=".">
        <path id="abc">
                        <pathelement location="resources/bsf-2.4.0.jar"/>
                        <pathelement location="resources/commons-logging.jar
"/>
                        <pathelement location="resources/groovy-all-1.0.jar
"/>
        </path>
  <target name="go">
          <script language="groovy" classpathref="abc">
      println "HELLO"
    </script>
  </target>
</project>

----------------------------------------------------------------------------
----
*
Next we run it and watch it error:*
$ ant
Buildfile: build.xml

go:

BUILD FAILED
c:\Documents and Settings\hperess\build.xml:10:
java.lang.NoClassDefFoundError: org/apache/bsf/BSFException

Total time: 0 seconds

----------------------------------------------------------------------------
----
*Finally, we run it but including the jars at call time.

*hperess@745-003 ~
$ ant -lib resources/
Buildfile: build.xml

go:
   [script] HELLO

BUILD SUCCESSFUL
Total time: 0 seconds

----------------------------------------------------------------------------
----
*Version info:*
hperess@745-003 ~
$ ant -version
Apache Ant version 1.7.0 compiled on December 13 2006

java version 1.6
----------------------------------------------------------------------------
----
*
QUESTION:
*
How can I run it so that I don't have to explicitely call ant with -lib??


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: classpath order wierdness

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

-----Original Message-----
From: Hunter Peress [mailto:hunterp@gmail.com] 
Sent: Tuesday, November 20, 2007 2:36 AM
To: Ant Users List
Subject: classpath order wierdness

/*

[ ... ]

QUESTION:
*
How can I run it so that I don't have to explicitely call ant with
-lib??

*/

Simply put all those jars, i.e. bsf.jar ... in %ANT_HOME%/lib


Regards,Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org