Reputation: 1109
I am trying to compile scala files from INSIDE their package folders.
So I have three files, Patient.scala
, PatientMonitor.scala
, and VitalSigns.scala
, they all reside in the following path gasguru/patient/
Here is my file VitalSigns.scala
// /gasguru/patient/VitalSigns.scala
package gasguru.patient
class VitalSigns () {
var heartRate = 0;
}
and I compile it with the following line: scalac -d ../.. VitalSigns.scala
this results in the VitalSigns.class
file being created in the same directory as I am currently in.
Now if I go to compile Patient.scala
which contains this:
// /gasguru/patient/Patient.scala
import gasguru.patient.VitalSigns;
package gasguru.patient {
class Patient ( val firstName:String, val lastName:String) {
val vitalSigns = new VitalSigns();
}
}
and if I try and compile it with this following line: scalac -d ../.. Patient.scala
I get the following error
Patient.scala:2: error: VitalSigns is not a member of gasguru.patient
import gasguru.patient.VitalSigns;
^
error: error while loading VitalSigns, Missing dependency 'class gasguru.patient.VitalSigns', required by ./VitalSigns.class
Patient.scala:6: error: VitalSigns does not have a constructor
val vitalSigns = new VitalSigns();
^
three errors found
Why am I getting this error when the VitalSigns.class
resides inside of the same directory as where I am compiling the file? Shouldn't importing it suffice?
Thanks!
EDIT:
chs@ubuntu:~/GasGuru/gasguru/patient$ ls
exceptions Patient.scala VitalSigns.scala
PatientMonitor.scala VitalSigns.class
Upvotes: 0
Views: 2003
Reputation: 297205
You are not passing the source file of VitalSigns.scala
as a parameter, so it will try to search for a classfile. The classfile of a class in the package x.y
is under the directory x/y
, which means it is trying to find gasguru/patient/VitalSigns.class
, which does not exist in the current directory you are at.
If you add -classpath ../..
, it should find the file.
Upvotes: 2