Reputation: 16825
import org.apache.tools.ant.Project
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
I tried to run this code 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
There is following error:
D:\test\scala\ant.scala:1: error: object apache is not a member of package org
import org.apache.tools.ant.Project
^
one error found
What is wrong?
UPDATE:
As I can see it is impossible to import any org.xxx package.
The same problem with javax.xml.xxx package.
D:\test\test2.scala:2: error: object crypto is not a member of package javax.xml
import javax.xml.crypto.Data
^
one error found
Actually I cannot import anything!
D:\test\test3.scala:3: error: object test is not a member of package com
import com.test.utils.ant.taskdefs.SqlExt
^
one error found
Upvotes: 3
Views: 19374
Reputation: 17141
I found that in general when an error of type Object XXX is not a member of package YYY
occurs, you should:
Check that all your files are in a package, ie. not in the top-level src/
directory
Upvotes: 2
Reputation: 2771
I experimented with scala.bat
(uncommenting the echo of the final command line, see the line starting with echo "%_JAVACMD%" ...
) and found that this should work:
java -Dscala.usejavacp=true -cp d:\Dev\scala-2.9.1.final\lib\scala-compiler.jar;d:\Dev\scala-2.9.1.final\lib\scala-library.jar scala.tools.nsc.MainGenericRunner -cp d:\Dev\apache-ant-1.8.2\lib\ant.jar D:\test\scala\ant.scala
Upvotes: 1
Reputation: 1184
Run with scala command instead:
scala -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 D:\test\scala\ant.scala
Upvotes: 0
Reputation: 12611
I would check that 'D:\tools\apache-ant-1.7.0\lib\ant.jar' exist and also check that it is not corrupt (length 0 or unable to open with 'jar tf D:\tools\apache-ant-1.7.0\lib\ant.jar').
Upvotes: 0
Reputation: 18167
You haven't included the ant jar file in your classpath.
The compiler effectively builds objects representing the nested package structure. There is already a top-level package named org from the JDK (org.xml for example) but without additional jars org.apache is not there.
Upvotes: 3