0

I am trying to compile the class "Example.scala" which has a dependency on the class "ProtocolLang.scala". I would like to do this without using sbt so I tried to use scalac directly on the command line. I tried making a jar from the ProtocolLang.scala class and then run:

scalac -classpath "LangJar.jar" Example.scala

The compiler does find "Example.scala" but does not seem to link it with the dependency and I get this error message:

Example.scala:3: error: not found: type ProtocolLang

The jar file is in the same directory as Example.scala and in the place I am calling the command. I used the command

jar cf LangJar.jar ProtocolLang.scala

to create the jar .

  • 1
    You have to add to classpath the directory where the _compiled class_ exists (so `.class` not `.scala`). If you cannot compile them separately because of e.g. cyclic dependencies, then you have to compile them at once. – Mateusz Kubuszok Jul 31 '20 at 13:46
  • Any reason for trying to do this manually instead of using a tool specially designed for managing this for you. – Luis Miguel Mejía Suárez Jul 31 '20 at 13:53
  • @MateuszKubuszok As in, when creating the jar or having "scalac -classpath "ProtocolLang.class" Example.scala"? – aurorarized Jul 31 '20 at 14:00
  • 1
    Both. JVM doesn't understand `.scala` files, and compiler cannot treat source code as classpath. – Mateusz Kubuszok Jul 31 '20 at 14:02
  • 1
    @LuisMiguelMejíaSuárez, I am trying to call the program (Example.scala) from within a compiler-plugin and I think if I was using sbt that would mean the user would have to have it and I would rather avoid that. Of course, I might be wrong, it just feels like there is a way of doing this with a simple scalac command, assuming I have the jar within the plugin. – aurorarized Jul 31 '20 at 14:04

0 Answers0