Scala的相对包裹进口

fbl*_*fbl 8 eclipse import scala package

我在eclipse中有一个多项目Scala工作区.我认为我对Scala导入软件包的方式缺乏了解,但是我花了更多的时间来考虑寻找解决方案后,我无法想象这一点.我在一个简单的2项目设置中重新创建了这个问题.

项目1:com.foo.mathematics包含一个简单的Vector类

包含一个文件:

package com.foo.mathematics    

class Vector2D(x : Double, y : Double) {



  def length = math.sqrt(x*x + y*y)

}
Run Code Online (Sandbox Code Playgroud)

项目2:com.foo.analysis

package com.foo.analysis

import com.foo.mathematics.Vector2D



class Frame(xAxis : Vector2D, yAxis : Vector2D) {



}
Run Code Online (Sandbox Code Playgroud)

Eclipse在导入行中显示错误,我得到的错误消息是:对象数学不是包com.foo的成员.

在大纲视图中,我的import语句说明了这一点:

com.foo.analysis.<error: <none>>.Vector2D
Run Code Online (Sandbox Code Playgroud)

我尝试将导入更改为:

import mathematics.Vector2D

import _root_.com.foo.mathematics.Vector2D
Run Code Online (Sandbox Code Playgroud)

两个人都没有......

我错过了什么?

Ale*_*nov 6

双方import com.foo.mathmatics.Vector2Dimport _root_.com.foo.mathmatics.Vector2D应罚款.很可能你没有将第一个项目添加到第二个项目的构建路径中(参见上下文菜单中的Build Path> Configure Build Path),或者需要在第一个项目中进行更改后清理第二个项目(Project> Build Clean).

(另外,mathmatics看起来像是一个错字mathematics,所以请仔细检查两个地方是否真的有相同的名字.)

相对包进口不会进入它,它们只是意味着你可以这样写:

package com.foo
package analysis
import mathmatics.Vector2D

class Frame(xAxis : Vector2D, yAxis : Vector2D) {

}
Run Code Online (Sandbox Code Playgroud)