- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Still problems trying to define scalatest task
Sat, 2009-08-01, 19:14
I have the following in my build.xml file:
<taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestTask"> <classpath> <pathelement location="/Library/Java/Extensions/scalatest.jar" /> <pathelement location="${scala.home}/lib/scala-compiler.jar" /> <pathelement location="${scala-library.jar}" /> </classpath> </taskdef>
This gives no static error or warnings (finally!), but when I try to run the file, I get:
/Users/Ken/Documents/workspace/rex/build.xml:44: taskdef A class needed by class org.scalatest.tools.ScalaTestTask cannot be found: org/apache/tools/ant/Task
where line 44 is the start of the 'scalatest' taskdef definition. Do I need to add in ant files to the path as well?
Thanks,Ken
<taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestTask"> <classpath> <pathelement location="/Library/Java/Extensions/scalatest.jar" /> <pathelement location="${scala.home}/lib/scala-compiler.jar" /> <pathelement location="${scala-library.jar}" /> </classpath> </taskdef>
This gives no static error or warnings (finally!), but when I try to run the file, I get:
/Users/Ken/Documents/workspace/rex/build.xml:44: taskdef A class needed by class org.scalatest.tools.ScalaTestTask cannot be found: org/apache/tools/ant/Task
where line 44 is the start of the 'scalatest' taskdef definition. Do I need to add in ant files to the path as well?
Thanks,Ken
Sat, 2009-08-01, 23:57
#2
Re: Still problems trying to define scalatest task
Hi Ken,
I'm not sure what is happening with your attempt, but I am successfully usingthe scalatest ant target in my Kiama project. You can find the build.xml here:
http://code.google.com/p/kiama/source/browse/build.xml
cheers,Tony
On 02/08/2009, at 4:13 AM, Kenneth McDonald wrote:
I'm not sure what is happening with your attempt, but I am successfully usingthe scalatest ant target in my Kiama project. You can find the build.xml here:
http://code.google.com/p/kiama/source/browse/build.xml
cheers,Tony
On 02/08/2009, at 4:13 AM, Kenneth McDonald wrote:
I have the following in my build.xml file:
<taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestTask"> <classpath> <pathelement location="/Library/Java/Extensions/scalatest.jar" /> <pathelement location="${scala.home}/lib/scala-compiler.jar" /> <pathelement location="${scala-library.jar}" /> </classpath> </taskdef>
This gives no static error or warnings (finally!), but when I try to run the file, I get:
/Users/Ken/Documents/workspace/rex/build.xml:44: taskdef A class needed by class org.scalatest.tools.ScalaTestTask cannot be found: org/apache/tools/ant/Task
where line 44 is the start of the 'scalatest' taskdef definition. Do I need to add in ant files to the path as well?
Thanks,Ken
Sun, 2009-08-02, 02:27
#3
Re: Still problems trying to define scalatest task
It's also interesting to note that the error message says it cannot find something that is a core class of the Ant distribution!:
Thanks again,Ken
Given the Eclipse includes its own copy of Ant, which it presumably knows where to find, any guesses as to how it could miss finding such a class?
/Users/Ken/Documents/workspace/rex/build.xml:44: taskdef A class needed by class org.scalatest.tools.ScalaTestTask cannot be found: org/apache/tools/ant/Task
Thanks again,Ken
Sun, 2009-08-02, 20:27
#4
Re: Still problems trying to define scalatest task
Hi Kenneth,
Sorry I was away from the net for a couple days. I think the problem
may be that you have put the scalatest.jar file in your Java standard
extensions directory, but haven't put the ant.jar file one there. The
JVM loads classes from Jar files located in the standard extensions
directory in its own class loader, which is a parent class loader from
the classpath class loader. The ScalaTest ant task indeed depends on
the ant Jar file, so it needs to be accessible from the same or a
parent class loader. So the solution would be to either move the
ScalaTest Jar file to the classpath, which is where Ant probably is,
or to put ant in the standard extensions directory. Give that a try
and let us know if it meets with success.
Bill
On Sat, Aug 1, 2009 at 11:13 AM, Kenneth
McDonald wrote:
> I have the following in my build.xml file:
>
>
>
>
>
>
>
> This gives no static error or warnings (finally!), but when I try to run the
> file, I get:
> /Users/Ken/Documents/workspace/rex/build.xml:44: taskdef A class needed by
> class org.scalatest.tools.ScalaTestTask cannot be found:
> org/apache/tools/ant/Task
> where line 44 is the start of the 'scalatest' taskdef definition. Do I need
> to add in ant files to the path as well?
> Thanks,
> Ken
Sun, 2009-08-02, 20:37
#5
Re: Still problems trying to define scalatest task
I believe Eclipse lets you specify a custom classpath in the Ant Build launch configuration dialog.
On Sun, Aug 2, 2009 at 3:25 PM, Bill Venners <bill@artima.com> wrote:
On Sun, Aug 2, 2009 at 3:25 PM, Bill Venners <bill@artima.com> wrote:
Hi Kenneth,
Sorry I was away from the net for a couple days. I think the problem
may be that you have put the scalatest.jar file in your Java standard
extensions directory, but haven't put the ant.jar file one there. The
JVM loads classes from Jar files located in the standard extensions
directory in its own class loader, which is a parent class loader from
the classpath class loader. The ScalaTest ant task indeed depends on
the ant Jar file, so it needs to be accessible from the same or a
parent class loader. So the solution would be to either move the
ScalaTest Jar file to the classpath, which is where Ant probably is,
or to put ant in the standard extensions directory. Give that a try
and let us know if it meets with success.
Bill
On Sat, Aug 1, 2009 at 11:13 AM, Kenneth
McDonald<kenneth.m.mcdonald@sbcglobal.net> wrote:
> I have the following in my build.xml file:
> <taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestTask">
> <classpath>
> <pathelement location="/Library/Java/Extensions/scalatest.jar" />
> <pathelement location="${scala.home}/lib/scala-compiler.jar" />
> <pathelement location="${scala-library.jar}" />
> </classpath>
> </taskdef>
> This gives no static error or warnings (finally!), but when I try to run the
> file, I get:
> /Users/Ken/Documents/workspace/rex/build.xml:44: taskdef A class needed by
> class org.scalatest.tools.ScalaTestTask cannot be found:
> org/apache/tools/ant/Task
> where line 44 is the start of the 'scalatest' taskdef definition. Do I need
> to add in ant files to the path as well?
> Thanks,
> Ken
--
Bill Venners
Artima, Inc.
http://www.artima.com
Sun, 2009-08-02, 21:27
#6
Re: Still problems trying to define scalatest task
Thanks for the replies, Bill and Naftoli. Don't apologize for being awayfrom the net on a weekend, that's probably a good thing :-)
I'm invoking Ant from the Eclipse UI, hence I assume it is probably usingthe ant file that comes bundled with Eclipse:
/Applications/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar
If I copy this file to the standard extensions directory, am I likely to create conflicts?I don't know enough about the classloader mechanism to answer this for myself.(Obviously I'd have to update when a new version of eclipse comes out, but that'sa problem for another day.)
Thanks,Ken
On Aug 2, 2009, at 2:28 PM, Naftoli Gugenheim wrote:
I'm invoking Ant from the Eclipse UI, hence I assume it is probably usingthe ant file that comes bundled with Eclipse:
/Applications/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar
If I copy this file to the standard extensions directory, am I likely to create conflicts?I don't know enough about the classloader mechanism to answer this for myself.(Obviously I'd have to update when a new version of eclipse comes out, but that'sa problem for another day.)
Thanks,Ken
On Aug 2, 2009, at 2:28 PM, Naftoli Gugenheim wrote:
I believe Eclipse lets you specify a custom classpath in the Ant Build launch configuration dialog.
On Sun, Aug 2, 2009 at 3:25 PM, Bill Venners <bill@artima.com> wrote:
Hi Kenneth,
Sorry I was away from the net for a couple days. I think the problem
may be that you have put the scalatest.jar file in your Java standard
extensions directory, but haven't put the ant.jar file one there. The
JVM loads classes from Jar files located in the standard extensions
directory in its own class loader, which is a parent class loader from
the classpath class loader. The ScalaTest ant task indeed depends on
the ant Jar file, so it needs to be accessible from the same or a
parent class loader. So the solution would be to either move the
ScalaTest Jar file to the classpath, which is where Ant probably is,
or to put ant in the standard extensions directory. Give that a try
and let us know if it meets with success.
Bill
On Sat, Aug 1, 2009 at 11:13 AM, Kenneth
McDonald<kenneth.m.mcdonald@sbcglobal.net> wrote:
> I have the following in my build.xml file:
> <taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestTask">
> <classpath>
> <pathelement location="/Library/Java/Extensions/scalatest.jar" />
> <pathelement location="${scala.home}/lib/scala-compiler.jar" />
> <pathelement location="${scala-library.jar}" />
> </classpath>
> </taskdef>
> This gives no static error or warnings (finally!), but when I try to run the
> file, I get:
> /Users/Ken/Documents/workspace/rex/build.xml:44: taskdef A class needed by
> class org.scalatest.tools.ScalaTestTask cannot be found:
> org/apache/tools/ant/Task
> where line 44 is the start of the 'scalatest' taskdef definition. Do I need
> to add in ant files to the path as well?
> Thanks,
> Ken
--
Bill Venners
Artima, Inc.
http://www.artima.com
Mon, 2009-08-03, 02:37
#7
Re: Still problems trying to define scalatest task
On Aug 2, 2009, at 2:25 PM, Bill Venners wrote:
Hi Kenneth,
Sorry I was away from the net for a couple days. I think the problem
may be that you have put the scalatest.jar file in your Java standard
extensions directory, but haven't put the ant.jar file one there.
Unfortunately, if I do this, the build fails to run at all—I don't even getan error message on the console. (That is, if I copy the ant.jar file fromthe Eclipse distro into /Library/Java/Extensions.) Presumably the JVMdoesn't like getting the same classes from two different sources. If, onthe other hand, I move scalatest.jar to the same eclipse directory thatcontains ant.jar, which would hopefully place it on the classpath, I getthe error:
/Users/Ken/Documents/workspace/rex/build.xml:34: taskdef class org.scalatest.tools.ScalaTestTask cannot be found
So presumably the file is not being found there.
I'm continuing to experiment, but if you have furthersuggestions, they'd be most appreciated.
Thanks,Ken
Mon, 2009-08-03, 02:47
#8
Re: Still problems trying to define scalatest task
On Aug 2, 2009, at 2:28 PM, Naftoli Gugenheim wrote:
> I believe Eclipse lets you specify a custom classpath in the Ant
> Build launch configuration dialog.
>
Do you mean like this?:
Mon, 2009-08-03, 04:07
#9
Re: Still problems trying to define scalatest task
One additional piece of info before I throw in the towel for the
night; this is apparently not an eclipse-related problem (or at least
not solely related to eclipse.) With great insight (yes, that's self-
directed sarcasm), I attempted the build using the command-line ant
tool. Results are as follows:
----------------
MBP:~ Ken$ cd Documents/workspace/rex
MBP:rex Ken$ ant build
Buildfile: build.xml
BUILD FAILED
/Users/Ken/Documents/workspace/rex/build.xml:69: taskdef A class
needed by class org.scalatest.tools.ScalaTestTask cannot be found: org/
apache/tools/ant/Task
Total time: 0 seconds
MBP:rex Ken$
--------------------
Once again, thanks for all the help, everyone.
Ken
Mon, 2009-08-03, 22:07
#10
Re: Still problems trying to define scalatest task
Hi Kenneth,
Sounds like you'll need to put scalatest.jar on the classpath instead
of in the standard extensions directory. The only thing in
scalatest.jar that needs ant is the ScalaTest ant task, but I have
always put the scalatest.jar on the classpath anyway. Perhaps the ant
task should be distributed differently, so that people could put
scalatest.jar in the standard extensions directory if they want. In
other words, the only part of scalatest.jar that you need to put on
the classpath is the ant task.
Bill
On Sun, Aug 2, 2009 at 6:27 PM, Kenneth
McDonald wrote:
>
> On Aug 2, 2009, at 2:25 PM, Bill Venners wrote:
>
> Hi Kenneth,
>
> Sorry I was away from the net for a couple days. I think the problem
> may be that you have put the scalatest.jar file in your Java standard
> extensions directory, but haven't put the ant.jar file one there.
>
> Unfortunately, if I do this, the build fails to run at all—I don't even get
> an error message on the console. (That is, if I copy the ant.jar file from
> the Eclipse distro into /Library/Java/Extensions.) Presumably the JVM
> doesn't like getting the same classes from two different sources. If, on
> the other hand, I move scalatest.jar to the same eclipse directory that
> contains ant.jar, which would hopefully place it on the classpath, I get
> the error:
> /Users/Ken/Documents/workspace/rex/build.xml:34: taskdef class
> org.scalatest.tools.ScalaTestTask cannot be found
> So presumably the file is not being found there.
> I'm continuing to experiment, but if you have further
> suggestions, they'd be most appreciated.
> Thanks,
> Ken
>
Mon, 2009-08-03, 22:47
#11
Re: Still problems trying to define scalatest task
On Aug 3, 2009, at 4:04 PM, Bill Venners wrote:
> Hi Kenneth,
>
> Sounds like you'll need to put scalatest.jar on the classpath instead
> of in the standard extensions directory. The only thing in
> scalatest.jar that needs ant is the ScalaTest ant task, but I have
> always put the scalatest.jar on the classpath anyway. Perhaps the ant
> task should be distributed differently, so that people could put
> scalatest.jar in the standard extensions directory if they want. In
> other words, the only part of scalatest.jar that you need to put on
> the classpath is the ant task.
>
> Bill
>
Hmm. Do you think problems are likely if I both leave it in the
extensions
directory AND put it on the classpath? Like I say, this part of Java is
black magic to me
Thanks,
Ken
Mon, 2009-08-03, 23:27
#12
Re: Still problems trying to define scalatest task
Hi Kenneth,
No I think you'll need to remove it from the standard extensions
directory, because a parent class loader always gets first shot at
loading the class.
http://www.artima.com/insidejvm/ed2/linkmod3.html
Thus if it is both on the classpath and in the standard extensions
directory, the ScalaTest ant task will still be loaded from the jar
file in the standard extensions directory. And that one can't find
ant, unless you also put ant.jar in the standard extensions directory.
I don't know why you can't do the latter, but it didn't run when you
tried it. So I think the best solution is just removing scalatest.jar
from the standard extensions directory entirely, and having it on the
classpath only.
Bill
On Mon, Aug 3, 2009 at 2:41 PM, Kenneth
McDonald wrote:
>
> On Aug 3, 2009, at 4:04 PM, Bill Venners wrote:
>
>> Hi Kenneth,
>>
>> Sounds like you'll need to put scalatest.jar on the classpath instead
>> of in the standard extensions directory. The only thing in
>> scalatest.jar that needs ant is the ScalaTest ant task, but I have
>> always put the scalatest.jar on the classpath anyway. Perhaps the ant
>> task should be distributed differently, so that people could put
>> scalatest.jar in the standard extensions directory if they want. In
>> other words, the only part of scalatest.jar that you need to put on
>> the classpath is the ant task.
>>
>> Bill
>>
> Hmm. Do you think problems are likely if I both leave it in the extensions
> directory AND put it on the classpath? Like I say, this part of Java is
> black magic to me
>
> Thanks,
> Ken
>
Mon, 2009-08-03, 23:47
#13
Re: Still problems trying to define scalatest task
On Aug 3, 2009, at 5:21 PM, Bill Venners wrote:
Hi Kenneth,
No I think you'll need to remove it from the standard extensions
directory, because a parent class loader always gets first shot at
loading the class.
When I delete scalatest.jar from the extensions directory, and then try to run one of my targets, I get:
[scalac] /Users/Ken/Documents/workspace/rex/test/ykken/rex/testrex.scala:2: error: value scalatest is not a member of package org [scalac] import org.scalatest.Suite
On the other hand, I can fire up scala, and import org.scalatest:
------------MBP:~ Ken$ scalaWelcome to Scala version 2.7.5.final (Java HotSpot(TM) Client VM, Java 1.5.0_19).Type in expressions to have them evaluated.Type :help for more information.
scala> import org.scalatestimport org.scalatest
scala> -------------
When I check my classpath, scalatest seems to be on it just fine:
---------------MBP:~ Ken$ env | grep CLASSCLASSPATH=/usr/share/ant/lib/ant.jar:/Applications/eclipse/scalatest.jarMBP:~ Ken$ ls -l /Applications/eclipse/scalatest.jar-rw-r--r--@ 1 Ken Ken 676587 Dec 24 2008 /Applications/eclipse/scalatest.jarMBP:~ Ken$ -----------------
This problem occurs with both ant under eclipse, and command-line ant. I'm stonkered. I'm going to go read your article on classloaders, but somehow doubt that will help :-) -- a little too advanced for me.
Thanks,Ken
Wed, 2009-08-05, 01:27
#14
Re: Still problems trying to define scalatest task
Hi Kenneth,
I don't think ant is using your CLASSPATH environment variable. When
you run something from within ant, you specify a classpath in that ant
task. Can you post the relevant part of your ant build.xml file?
Bill
On Mon, Aug 3, 2009 at 3:40 PM, Kenneth
McDonald wrote:
>
> On Aug 3, 2009, at 5:21 PM, Bill Venners wrote:
>
> Hi Kenneth,
>
> No I think you'll need to remove it from the standard extensions
> directory, because a parent class loader always gets first shot at
> loading the class.
>
> When I delete scalatest.jar from the extensions directory, and then try to
> run one of my targets, I get:
> [scalac]
> /Users/Ken/Documents/workspace/rex/test/ykken/rex/testrex.scala:2: error:
> value scalatest is not a member of package org
> [scalac] import org.scalatest.Suite
> On the other hand, I can fire up scala, and import org.scalatest:
> ------------
> MBP:~ Ken$ scala
> Welcome to Scala version 2.7.5.final (Java HotSpot(TM) Client VM, Java
> 1.5.0_19).
> Type in expressions to have them evaluated.
> Type :help for more information.
> scala> import org.scalatest
> import org.scalatest
> scala>
> -------------
> When I check my classpath, scalatest seems to be on it just fine:
> ---------------
> MBP:~ Ken$ env | grep CLASS
> CLASSPATH=/usr/share/ant/lib/ant.jar:/Applications/eclipse/scalatest.jar
> MBP:~ Ken$ ls -l /Applications/eclipse/scalatest.jar
> -rw-r--r--@ 1 Ken Ken 676587 Dec 24 2008
> /Applications/eclipse/scalatest.jar
> MBP:~ Ken$
> -----------------
> This problem occurs with both ant under eclipse, and command-line ant. I'm
> stonkered. I'm going to go read your article on classloaders, but somehow
> doubt that will help :-) -- a little too advanced for me.
> Thanks,
> Ken
>
>
Wed, 2009-08-05, 22:27
#15
Re: Still problems trying to define scalatest task
Bill,
Thanks for all your patience. Here's the current error I'm getting:
---------------MBP:rex Ken$ ant test2Buildfile: build.xml
build: [scalac] Compiling 1 source file to /Users/Ken/Documents/workspace/rex/build
test2:
BUILD FAILED/Users/Ken/Documents/workspace/rex/build.xml:91: java.lang.NoClassDefFoundError: scala/ScalaObject
Total time: 10 seconds---------------
and here is the complete build file: line 91 is "scalatest" inside of "test2"
Thanks,Ken
------------------<?xml version="1.0" encoding="UTF-8"?><project name="Rex" default="build" basedir="."> <description> simple test to build Scala project </description>
<!-- Common paths --> <property name="src.dir" value="${basedir}/src" /> <property name="build.dir" value="${basedir}/build" /> <property name="jar.dir" value="${basedir}/jar" /> <property name="doc.dir" value="${basedir}/doc" /> <property name="test.dir" value="${basedir}/test" /> <property name="testclasses.dir" value="${basedir}/testclasses" />
<!-- Scala CLASSPATH --> <property name="scala.home" value="/Applications/scala" /> <property name="scala-compiler.jar" value="${scala.home}/lib/scala-compiler.jar" /> <property name="scala-library.jar" value="${scala.home}/lib/scala-library.jar" /> <path id="scala.classpath"> <pathelement location="${scala-compiler.jar}" /> <pathelement location="${scala-library.jar}" /> </path>
<!-- Project CLASSPATH --> <path id="project.classpath"> <path refid="scala.classpath" /> <pathelement location="${build.dir}" /> </path>
<taskdef resource="scala/tools/ant/antlib.xml"> <classpath> <pathelement location="${scala.home}/lib/scala-compiler.jar" /> <pathelement location="${scala-library.jar}" /> </classpath> </taskdef>
<taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestTask"> <classpath> <pathelement location="${scala.home}/lib/scala-compiler.jar" /> <pathelement location="${scala-library.jar}" /> <pathelement location="/Applications/eclipse/scalatest.jar" /> </classpath> </taskdef> <!-- TARGETS -->
<target name="clean"> <delete dir="${build.dir}" /> <delete dir="${jar.dir}" /> <delete dir="${doc.dir}" /> <delete dir="${testclasses.dir}" /> </target>
<target name="build"> <mkdir dir="${build.dir}" /> <scalac srcdir="${src.dir}" destdir="${build.dir}" classpathref="http://www.scala-lang.org/project.classpath#" force="changed"> <classpath> <pathelement location="/Applications/eclipse/scalatest.jar" /> </classpath> <include name="**/*.scala" /> </scalac> </target>
<target name="buildwithtests" depends="build"> <mkdir dir="${testclasses.dir}" /> <scalac srcdir="${test.dir}" destdir="${testclasses.dir}" classpathref="http://www.scala-lang.org/project.classpath#" force="changed"> <include name="**/*.scala" /> </scalac> </target>
<!-- scalac ykken/rex/testrex.scala -classpath ../jar/rex.jar -->
<target name="jar" depends="build"> <mkdir dir="${jar.dir}" /> <jar destfile="${jar.dir}/rex.jar" basedir="${build.dir}" /> </target>
<target name="test" depends="build"> <mkdir dir="${jar.dir}" /> <jar destfile="${jar.dir}/rex.jar"> <fileset dir="${build.dir}" /> <fileset dir="${test.dir}" /> </jar> </target>
<target name="doc"> <mkdir dir="${doc.dir}" /> <scaladoc srcdir="${src.dir}" destdir="${doc.dir}" classpathref="http://www.scala-lang.org/project.classpath#" header="rex 0.95"> <include name="**/*.scala" /> </scaladoc> </target>
<target name="test2" depends="build"> <scalatest> <reporter type="stdout" config="FAB"/> <runpath> <pathelement location="$jar.dir/rex.jar" /> </runpath> </scalatest> </target>
</project>
On Aug 4, 2009, at 7:23 PM, Bill Venners wrote:
Thanks for all your patience. Here's the current error I'm getting:
---------------MBP:rex Ken$ ant test2Buildfile: build.xml
build: [scalac] Compiling 1 source file to /Users/Ken/Documents/workspace/rex/build
test2:
BUILD FAILED/Users/Ken/Documents/workspace/rex/build.xml:91: java.lang.NoClassDefFoundError: scala/ScalaObject
Total time: 10 seconds---------------
and here is the complete build file: line 91 is "scalatest" inside of "test2"
Thanks,Ken
------------------<?xml version="1.0" encoding="UTF-8"?><project name="Rex" default="build" basedir="."> <description> simple test to build Scala project </description>
<!-- Common paths --> <property name="src.dir" value="${basedir}/src" /> <property name="build.dir" value="${basedir}/build" /> <property name="jar.dir" value="${basedir}/jar" /> <property name="doc.dir" value="${basedir}/doc" /> <property name="test.dir" value="${basedir}/test" /> <property name="testclasses.dir" value="${basedir}/testclasses" />
<!-- Scala CLASSPATH --> <property name="scala.home" value="/Applications/scala" /> <property name="scala-compiler.jar" value="${scala.home}/lib/scala-compiler.jar" /> <property name="scala-library.jar" value="${scala.home}/lib/scala-library.jar" /> <path id="scala.classpath"> <pathelement location="${scala-compiler.jar}" /> <pathelement location="${scala-library.jar}" /> </path>
<!-- Project CLASSPATH --> <path id="project.classpath"> <path refid="scala.classpath" /> <pathelement location="${build.dir}" /> </path>
<taskdef resource="scala/tools/ant/antlib.xml"> <classpath> <pathelement location="${scala.home}/lib/scala-compiler.jar" /> <pathelement location="${scala-library.jar}" /> </classpath> </taskdef>
<taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestTask"> <classpath> <pathelement location="${scala.home}/lib/scala-compiler.jar" /> <pathelement location="${scala-library.jar}" /> <pathelement location="/Applications/eclipse/scalatest.jar" /> </classpath> </taskdef> <!-- TARGETS -->
<target name="clean"> <delete dir="${build.dir}" /> <delete dir="${jar.dir}" /> <delete dir="${doc.dir}" /> <delete dir="${testclasses.dir}" /> </target>
<target name="build"> <mkdir dir="${build.dir}" /> <scalac srcdir="${src.dir}" destdir="${build.dir}" classpathref="http://www.scala-lang.org/project.classpath#" force="changed"> <classpath> <pathelement location="/Applications/eclipse/scalatest.jar" /> </classpath> <include name="**/*.scala" /> </scalac> </target>
<target name="buildwithtests" depends="build"> <mkdir dir="${testclasses.dir}" /> <scalac srcdir="${test.dir}" destdir="${testclasses.dir}" classpathref="http://www.scala-lang.org/project.classpath#" force="changed"> <include name="**/*.scala" /> </scalac> </target>
<!-- scalac ykken/rex/testrex.scala -classpath ../jar/rex.jar -->
<target name="jar" depends="build"> <mkdir dir="${jar.dir}" /> <jar destfile="${jar.dir}/rex.jar" basedir="${build.dir}" /> </target>
<target name="test" depends="build"> <mkdir dir="${jar.dir}" /> <jar destfile="${jar.dir}/rex.jar"> <fileset dir="${build.dir}" /> <fileset dir="${test.dir}" /> </jar> </target>
<target name="doc"> <mkdir dir="${doc.dir}" /> <scaladoc srcdir="${src.dir}" destdir="${doc.dir}" classpathref="http://www.scala-lang.org/project.classpath#" header="rex 0.95"> <include name="**/*.scala" /> </scaladoc> </target>
<target name="test2" depends="build"> <scalatest> <reporter type="stdout" config="FAB"/> <runpath> <pathelement location="$jar.dir/rex.jar" /> </runpath> </scalatest> </target>
</project>
On Aug 4, 2009, at 7:23 PM, Bill Venners wrote:
Hi Kenneth,
I don't think ant is using your CLASSPATH environment variable. When
you run something from within ant, you specify a classpath in that ant
task. Can you post the relevant part of your ant build.xml file?
Bill
On Mon, Aug 3, 2009 at 3:40 PM, Kenneth
McDonald<kenneth.m.mcdonald@sbcglobal.net> wrote:On Aug 3, 2009, at 5:21 PM, Bill Venners wrote:Hi Kenneth,No I think you'll need to remove it from the standard extensionsdirectory, because a parent class loader always gets first shot atloading the class.When I delete scalatest.jar from the extensions directory, and then try torun one of my targets, I get:[scalac]/Users/Ken/Documents/workspace/rex/test/ykken/rex/testrex.scala:2: error:value scalatest is not a member of package org[scalac] import org.scalatest.SuiteOn the other hand, I can fire up scala, and import org.scalatest:------------MBP:~ Ken$ scalaWelcome to Scala version 2.7.5.final (Java HotSpot(TM) Client VM, Java1.5.0_19).Type in expressions to have them evaluated.Type :help for more information.scala> import org.scalatestimport org.scalatestscala>-------------When I check my classpath, scalatest seems to be on it just fine:---------------MBP:~ Ken$ env | grep CLASSCLASSPATH=/usr/share/ant/lib/ant.jar:/Applications/eclipse/scalatest.jarMBP:~ Ken$ ls -l /Applications/eclipse/scalatest.jar-rw-r--r--@ 1 Ken Ken 676587 Dec 24 2008/Applications/eclipse/scalatest.jarMBP:~ Ken$-----------------This problem occurs with both ant under eclipse, and command-line ant. I'mstonkered. I'm going to go read your article on classloaders, but somehowdoubt that will help :-) -- a little too advanced for me.Thanks,Ken
--
Bill Venners
Artima, Inc.
http://www.artima.com
Fri, 2009-08-07, 18:37
#16
Re: Still problems trying to define scalatest task
Hi Kenneth,
Sorry for the delay in responding. It took us some time to reproduce this, and it was an basically an accident that it actually manifested itself for us. I'm not sure if this is your problem, but let me explain the problem we saw. We don't see any problem at all in your build.xml file.
The error message you're seeing means that you are trying to use compiled Scala code (from ScalaTest via the ScalaTest ant task), but scala-library.jar is not available:
java.lang.NoClassDefFoundError: scala/ScalaObject
The scala/ScalaObject interface is in scala-library.jar. Here's how we reproduced it. If we create a CLASSPATH environment variable, and put scalatest.jar on the CLASSPATH, but not scala-library.jar, then we get the same error you saw. If this is what you were doing, to solve this, you can either add scala-library.jar to the CLASSPATH environment variable (and any other dependencies that you get complaints about), or remove scalatest.jar from it. Either way that would get your build to work. Another possibility, since you were using the standard extensions directory, is you've put scalatest.jar in the standard extensions directory, but not scala-library.jar. If this is your situation, then you should be able to fix it in the same way (I'd remove scalatest.jar from that directory, or the classpath, whichever is your situation, rather than try and add scala-library.jar).
As far as an explanation, I can venture a guess at this point. Ant probably creates a custom class loader to load tasks, which also loads the jar files you mention in your taskdef. (You mention scalatest.jar, scala-library.jar, and scala-compiler.jar.) Before this class loader tries to load a class, it will delegate to its parent. It's parent, or its grandparent, or someone up its chain is the classpath class loader that is loading things mentioned in the environment variable. Well if scalatest.jar is available on the classpath via the environment variable, than that loader will load the ScalaTest classes, which refer to things in scala-library.jar. But the that loader can't find scala-library.jar, because it is further down the chain. So you get the error message.
Please let us know if this information helps you solve your problem.
Thanks.
Bill
On Wed, Aug 5, 2009 at 2:20 PM, Kenneth McDonald <kenneth.m.mcdonald@sbcglobal.net> wrote:
--
Bill Venners
Artima, Inc.
http://www.artima.com
Sorry for the delay in responding. It took us some time to reproduce this, and it was an basically an accident that it actually manifested itself for us. I'm not sure if this is your problem, but let me explain the problem we saw. We don't see any problem at all in your build.xml file.
The error message you're seeing means that you are trying to use compiled Scala code (from ScalaTest via the ScalaTest ant task), but scala-library.jar is not available:
java.lang.NoClassDefFoundError: scala/ScalaObject
The scala/ScalaObject interface is in scala-library.jar. Here's how we reproduced it. If we create a CLASSPATH environment variable, and put scalatest.jar on the CLASSPATH, but not scala-library.jar, then we get the same error you saw. If this is what you were doing, to solve this, you can either add scala-library.jar to the CLASSPATH environment variable (and any other dependencies that you get complaints about), or remove scalatest.jar from it. Either way that would get your build to work. Another possibility, since you were using the standard extensions directory, is you've put scalatest.jar in the standard extensions directory, but not scala-library.jar. If this is your situation, then you should be able to fix it in the same way (I'd remove scalatest.jar from that directory, or the classpath, whichever is your situation, rather than try and add scala-library.jar).
As far as an explanation, I can venture a guess at this point. Ant probably creates a custom class loader to load tasks, which also loads the jar files you mention in your taskdef. (You mention scalatest.jar, scala-library.jar, and scala-compiler.jar.) Before this class loader tries to load a class, it will delegate to its parent. It's parent, or its grandparent, or someone up its chain is the classpath class loader that is loading things mentioned in the environment variable. Well if scalatest.jar is available on the classpath via the environment variable, than that loader will load the ScalaTest classes, which refer to things in scala-library.jar. But the that loader can't find scala-library.jar, because it is further down the chain. So you get the error message.
Please let us know if this information helps you solve your problem.
Thanks.
Bill
On Wed, Aug 5, 2009 at 2:20 PM, Kenneth McDonald <kenneth.m.mcdonald@sbcglobal.net> wrote:
Bill,
Thanks for all your patience. Here's the current error I'm getting:
---------------MBP:rex Ken$ ant test2Buildfile: build.xml
build: [scalac] Compiling 1 source file to /Users/Ken/Documents/workspace/rex/build
test2:
BUILD FAILED/Users/Ken/Documents/workspace/rex/build.xml:91: java.lang.NoClassDefFoundError: scala/ScalaObject
Total time: 10 seconds ---------------
and here is the complete build file: line 91 is "scalatest" inside of "test2"
Thanks,Ken
------------------<?xml version="1.0" encoding="UTF-8"?> <project name="Rex" default="build" basedir="."> <description> simple test to build Scala project </description>
<!-- Common paths --> <property name="src.dir" value="${basedir}/src" /> <property name="build.dir" value="${basedir}/build" /> <property name="jar.dir" value="${basedir}/jar" /> <property name="doc.dir" value="${basedir}/doc" /> <property name="test.dir" value="${basedir}/test" /> <property name="testclasses.dir" value="${basedir}/testclasses" />
<!-- Scala CLASSPATH --> <property name="scala.home" value="/Applications/scala" /> <property name="scala-compiler.jar" value="${scala.home}/lib/scala-compiler.jar" /> <property name="scala-library.jar" value="${scala.home}/lib/scala-library.jar" /> <path id="scala.classpath"> <pathelement location="${scala-compiler.jar}" /> <pathelement location="${scala-library.jar}" /> </path>
<!-- Project CLASSPATH --> <path id="project.classpath"> <path refid="scala.classpath" /> <pathelement location="${build.dir}" /> </path>
<taskdef resource="scala/tools/ant/antlib.xml"> <classpath> <pathelement location="${scala.home}/lib/scala-compiler.jar" /> <pathelement location="${scala-library.jar}" /> </classpath> </taskdef>
<taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestTask"> <classpath> <pathelement location="${scala.home}/lib/scala-compiler.jar" /> <pathelement location="${scala-library.jar}" /> <pathelement location="/Applications/eclipse/scalatest.jar" /> </classpath> </taskdef> <!-- TARGETS -->
<target name="clean"> <delete dir="${build.dir}" /> <delete dir="${jar.dir}" /> <delete dir="${doc.dir}" /> <delete dir="${testclasses.dir}" /> </target>
<target name="build"> <mkdir dir="${build.dir}" /> <scalac srcdir="${src.dir}" destdir="${build.dir}" classpathref="project.classpath" force="changed"> <classpath> <pathelement location="/Applications/eclipse/scalatest.jar" /> </classpath> <include name="**/*.scala" /> </scalac> </target>
<target name="buildwithtests" depends="build"> <mkdir dir="${testclasses.dir}" /> <scalac srcdir="${test.dir}" destdir="${testclasses.dir}" classpathref="project.classpath" force="changed"> <include name="**/*.scala" /> </scalac> </target>
<!-- scalac ykken/rex/testrex.scala -classpath ../jar/rex.jar -->
<target name="jar" depends="build"> <mkdir dir="${jar.dir}" /> <jar destfile="${jar.dir}/rex.jar" basedir="${build.dir}" /> </target>
<target name="test" depends="build"> <mkdir dir="${jar.dir}" /> <jar destfile="${jar.dir}/rex.jar"> <fileset dir="${build.dir}" /> <fileset dir="${test.dir}" /> </jar> </target>
<target name="doc"> <mkdir dir="${doc.dir}" /> <scaladoc srcdir="${src.dir}" destdir="${doc.dir}" classpathref="project.classpath" header="rex 0.95"> <include name="**/*.scala" /> </scaladoc> </target>
<target name="test2" depends="build"> <scalatest> <reporter type="stdout" config="FAB"/> <runpath> <pathelement location="$jar.dir/rex.jar" /> </runpath> </scalatest> </target>
</project>
On Aug 4, 2009, at 7:23 PM, Bill Venners wrote:Hi Kenneth,
I don't think ant is using your CLASSPATH environment variable. When
you run something from within ant, you specify a classpath in that ant
task. Can you post the relevant part of your ant build.xml file?
Bill
On Mon, Aug 3, 2009 at 3:40 PM, Kenneth
McDonald<kenneth.m.mcdonald@sbcglobal.net> wrote:
On Aug 3, 2009, at 5:21 PM, Bill Venners wrote:Hi Kenneth,No I think you'll need to remove it from the standard extensionsdirectory, because a parent class loader always gets first shot at
loading the class.When I delete scalatest.jar from the extensions directory, and then try torun one of my targets, I get:[scalac]/Users/Ken/Documents/workspace/rex/test/ykken/rex/testrex.scala:2: error:
value scalatest is not a member of package org[scalac] import org.scalatest.SuiteOn the other hand, I can fire up scala, and import org.scalatest:
------------MBP:~ Ken$ scalaWelcome to Scala version 2.7.5.final (Java HotSpot(TM) Client VM, Java
1.5.0_19).Type in expressions to have them evaluated.Type :help for more information.scala> import org.scalatestimport org.scalatestscala>-------------
When I check my classpath, scalatest seems to be on it just fine:---------------MBP:~ Ken$ env | grep CLASS
CLASSPATH=/usr/share/ant/lib/ant.jar:/Applications/eclipse/scalatest.jarMBP:~ Ken$ ls -l /Applications/eclipse/scalatest.jar-rw-r--r--@ 1 Ken Ken 676587 Dec 24 2008/Applications/eclipse/scalatest.jarMBP:~ Ken$-----------------
This problem occurs with both ant under eclipse, and command-line ant. I'mstonkered. I'm going to go read your article on classloaders, but somehow
doubt that will help :-) -- a little too advanced for me.Thanks,Ken
--
Bill Venners
Artima, Inc.
http://www.artima.com
--
Bill Venners
Artima, Inc.
http://www.artima.com
Following a simple directories structure and adding one simple line of code:
require 'buildr/scala'
You are sure that everything(srcs and tests) works fine. I love it.
Regards,
# AliPanickSent from my iPhone On 01/ago/2009, at 20.13, Kenneth McDonald <kenneth.m.mcdonald@sbcglobal.net> wrote: