scala 对象 apache 不是包 org 的成员

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8211619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 03:41:39  来源:igfitidea点击:

Object apache is not a member of package org

scala

提问by Volodymyr Bezuglyy

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.

更新:
正如我所见,无法导入任何 org.xxx 包。
javax.xml.xxx 包也有同样的问题。

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

采纳答案by Eugen Labun

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:

我尝试了scala.bat(取消注释最终命令行的回声,查看以 开头的行echo "%_JAVACMD%" ...)并发现这应该有效:

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

回答by Duncan McGregor

You haven't included the ant jar file in your classpath.

您尚未在类路径中包含 ant jar 文件。

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.

编译器有效地构建表示嵌套包结构的对象。JDK 中已经有一个名为 org 的顶级包(例如 org.xml),但没有额外的 jars org.apache 不存在。

回答by BAR

I found that in general when an error of type Object XXX is not a member of package YYYoccurs, you should:

我发现一般来说,当Object XXX is not a member of package YYY发生类型错误时,您应该:

Check that all your files are in a package, ie. not in the top-level src/directory

检查您的所有文件是否都在一个包中,即。不在顶级src/目录中

回答by thoredge

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').

我会检查“D:\tools\apache-ant-1.7.0\lib\ant.jar”是否存在,并检查它是否已损坏(长度为 0 或无法使用“jar tf D:\tools\apache”打开) -ant-1.7.0\lib\ant.jar')。

回答by Lex

Run with scala command instead:

改为使用 scala 命令运行:

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

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