This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Object XXX is not a member of package YYY

6 replies
vbez
Joined: 2009-10-04,
User offline. Last seen 49 weeks 4 days ago.

I tried to write first lines in Scala and failed.

import org.apache.tools.ant.Project
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}

I've got "object apache is not a member of package org" error when I
tried to run this script using following command:
java -cp D:\tools\apache-ant-1.7.0\lib\ant.jar;D:\tools
\scala-2.9.1.final\lib\scala-compiler.jar;D:\tools\scala-2.9.1.final
\lib\scala-library.jar -Dscala.usejavacp=true
scala.tools.nsc.MainGenericRunner D:\test\scala\ant.scala

The same for "import javax.xml.crypto.Data" - "object crypto is not a
member of package javax.xml".

I asked about this problem here -
http://stackoverflow.com/questions/8211619/object-apache-is-not-a-member...
But did not get the answer yet.

Peter 2
Joined: 2011-02-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Object XXX is not a member of package YYY

Though I'm not a script user, I'd try to run bin\scala.bat with the
syntax described at http://www.scala-lang.org/docu/files/tools/scala.html.

Peter

E. Labun
Joined: 2010-06-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Object XXX is not a member of package YYY

Hi Vladimir,

this works for me:

java -cp
D:\tools\scala-2.9.1.final\lib\scala-compiler.jar;D:\tools\scala-2.9.1.final\lib\scala-library.jar
-Dscala.usejavacp=true scala.tools.nsc.MainGenericRunner -cp D:\tools\apache-ant-1.7.0\lib\ant.jar
D:\test\scala\ant.scala

Don't know whether it's a bug or expected behavior, that the MainGenericRunner doesn't use the java
classpath in your original example.

--
Eugen

barden
Joined: 2010-03-30,
User offline. Last seen 33 weeks 5 days ago.
creating instances from methods relying on abstract classes

Hi all,

I wonder whether the following is a well known pattern or not so smart as I think it was during creating it (and by the way due to the for and back linking between classes and companions I was surprised that it is firstly compiling and secondly working ;-). Is there a more transparent way of doing it?

Thanks and Regards,
Volker.

+------------

I have a lot of classes coming from one abstract one. Because all of them need a popper companion with certain methods I added also a blueprint for the companion:

trait PetCompanion[A] {
def apply(name: String): A
def unapply(a: Pet[A]) = Some(a.kind)
}

abstract class Pet[A](val kind: String, val name: String) {
def companion: PetCompanion[A]
def sound: String
def bear(name: String) = companion("son of " + name)
override def toString = name + ": " + sound
}

Now I can create Dog

object Dog extends PetCompanion[Dog] {def apply(name: String) = new Dog(name)}

class Dog(name: String) extends Pet[Dog]("Dog", name) {
override val companion = Dog
override val sound = "woof"
}

and Cat classes/companions

object Cat extends PetCompanion[Cat] {def apply(name: String) = new Cat(name)}

class Cat(name: String) extends Pet[Cat]("Cat", name) {
override val companion = Cat
override val sound = "miaow"
}

The benefit is that I can write functions returning instances of pets depending on the input like:

def create[A <: Pet[A]](companion: PetCompanion[A])(name: String) = companion(name)

Or in action:

scala> create(Dog)("Spike")
res0: Dog = Spike: woof

scala> create(Cat)("Tom")
res1: Cat = Tom: miaow

vbez
Joined: 2009-10-04,
User offline. Last seen 49 weeks 4 days ago.
Re: Object XXX is not a member of package YYY
On Wed, Nov 23, 2011 at 4:27 PM, Eugen Labun <labun@gmx.net> wrote:
this works for me:
 java -cp D:\tools\scala-2.9.1.final\lib\scala-compiler.jar;D:\tools\scala-2.9.1.final\lib\scala-library.jar -Dscala.usejavacp=true scala.tools.nsc.MainGenericRunner -cp D:\tools\apache-ant-1.7.0\lib\ant.jar D:\test\scala\ant.scala

Thank you very much!It helps.
Does anyone can explain this feature?

Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: Object XXX is not a member of package YYY
Scala has a standard library that includes java's standard library.  Ant is not part of this.  If you want to use ant classes, you have to tell the compiler/runtime where ant is.

On Wed, Nov 23, 2011 at 10:53 AM, Vladimir Bezugliy <vladimirbezugliy@gmail.com> wrote:
On Wed, Nov 23, 2011 at 4:27 PM, Eugen Labun <labun@gmx.net> wrote:
this works for me:
 java -cp D:\tools\scala-2.9.1.final\lib\scala-compiler.jar;D:\tools\scala-2.9.1.final\lib\scala-library.jar -Dscala.usejavacp=true scala.tools.nsc.MainGenericRunner -cp D:\tools\apache-ant-1.7.0\lib\ant.jar D:\test\scala\ant.scala

Thank you very much!It helps.
Does anyone can explain this feature?


E. Labun
Joined: 2010-06-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Object XXX is not a member of package YYY

But ant.jar *was* in the java classpath, and the environment variable "scala.usejavacp" was set to
true (see the original post). So, why Scala's MainGenericRunner couldn't use classes from the java
classpath and needed specifying its own classpath additionally to the java classpath? Or am I
missing something?

On 2011-11-23 16:57, Josh Suereth wrote:
> Scala has a standard library that includes java's standard library. Ant is not part of this. If
> you want to use ant classes, you have to tell the compiler/runtime where ant is.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland