Import packages from ensime inferior scala buffer

90 views
Skip to first unread message

wrn....@gmail.com

unread,
Aug 13, 2015, 2:04:59 PM8/13/15
to ENSIME
I am new to Scala and ENSIME, but an experience Emacs user. I am trying to set up my Emacs properly for experimenting with Scala. I set up a project and things seem to work (on the fly compilation, auto completion, can do sbt-command and etc). However, I found that in my ensime inferior buffer (launched with M-x ensime-inf-run-scala), I cannot import any of my packages defined in the project, while I can do that in a sbt console. The classpath from (ensime-inf-get-repl-cmd-line)looks good (points to my project class directory). Can somebody show me how to fix that? This is on Windows Emacs 24.5 and a very recent Ensime/SBT. Thank you.

Sam Halliday

unread,
Aug 14, 2015, 8:44:51 AM8/14/15
to ENSIME, wrn....@gmail.com
Do you just get class missing errors? I assume you've compiled your project so the class binaries are there. If you can reproduce with a minimal project on github, that would be useful.

BTW the mailing list is not very active, you will probably get a lot more responses if you ask on gitter or the issue tracker generally.

wrn....@gmail.com

unread,
Aug 14, 2015, 4:52:07 PM8/14/15
to ENSIME, wrn....@gmail.com
Bsically, I just get an error like this:


scala> import greeter.Hello
<console>:7: error: not found: value greeter
import greeter.Hello
^

I even used the ":cp" command to add explicitly the classpath, and I verified the classes have been compiled (sbt run has no issues) there. Do I have to put all the classes into a .jar file? (I did not do that)

Thanks for the suggestion for the other venue to post this question.

wrn....@gmail.com

unread,
Aug 14, 2015, 11:34:06 PM8/14/15
to ENSIME, wrn....@gmail.com
I found what the issue is, by comparing the java command line from invoking
scala -cp <my_project_class_path>
to the command line ensime-inf-run-scala generated.

I found that even with
"-Dscala.usejavacp=true" in the java command line for launching scala, I need to repeat the same class path at the end (as the argument to the scala REPL main class), so it will be something like this:

"c:\Program Files\Java\jdk1.8.0_51/bin/java" "-Xmx512M" "-XX:MaxPermSize=256m" "-XX:ReservedCodeCacheSize=128m" "-Dsbt.log.format=true" "-classpath" ";C:\wlin\projects\scala\hello\target\scala-2.11\classes;C:\wlin\projects\scala\hello\target\scala-2.11\test-classes;c:\Program Files (x86)\scala\lib\scala-library.jar" "-classpath" ";c:/Program Files (x86)/scala/lib/*" "-Dscala.usejavacp=true" "scala.tools.nsc.MainGenericRunner" "-Xnojline" "-cp" ";C:\wlin\projects\scala\hello\target\scala-2.11\classes;C:\wlin\projects\scala\hello\target\scala-2.11\test-classes;c:\Program Files (x86)\scala\lib\scala-library.jar"

By the way, I also need to add
"-classpath" ";c:/Program Files (x86)/scala/lib/*"
to the original ENSIME command line to make it work (otherwise scala REPL won't start at all because of some missing classes). I did not mention that in my very first post in this thread.

This is tested on Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_51), on Windows 7 home edition.

Seems to me like a Scala bug (and also an ENSIME bug too that won't even start Scala REPL at all). If that is true, I am in a bit shock to realize that the code quality is so low as Scala is deemed mature. But I am a newbie here, so very likely I misunderstood something. Hope the experts can tell me the other way. Thanks.

Seth Tisue

unread,
Aug 15, 2015, 2:48:58 PM8/15/15
to ens...@googlegroups.com
it’s not clear to me what you think the Scala bug is here…?

Sam Halliday

unread,
Aug 15, 2015, 5:59:02 PM8/15/15
to ens...@googlegroups.com

Yeah, me either. Can you please create a set of step by step instructions for this? Ideally report this on github.

On 15 Aug 2015 7:48 pm, "Seth Tisue" <seth....@typesafe.com> wrote:
it’s not clear to me what you think the Scala bug is here…?

--
You received this message because you are subscribed to a topic in the Google Groups "ENSIME" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ensime/_K-rJ8jsYXs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ensime+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wrn....@gmail.com

unread,
Aug 17, 2015, 10:00:49 AM8/17/15
to ENSIME
The Scala bug (I think) is: when -Dscala.usejavacp is set to true, the classpath in the java command line arguments should also be used as classpath for Scala to import packages. But in my test, that did not work, hence I need to repeat the classpath at the end of the command line, to supply the classpath again into Scala.

The Ensime bug is: out of the box it simply won't start the inf Scala buffer, unless I add extra classpath to it.

Note above is all tested on Windows 7. Did not try it on Windows.

Thanks.

wrn....@gmail.com

unread,
Aug 17, 2015, 10:03:04 AM8/17/15
to ENSIME
Sorry I meant "did not try it on Linux"

Seth Tisue

unread,
Aug 19, 2015, 4:30:30 PM8/19/15
to ENSIME, wrn....@gmail.com
On Monday, August 17, 2015 at 10:00:49 AM UTC-4, wrn....@gmail.com wrote:
>The Scala bug (I think) is: when -Dscala.usejavacp is set to true, the classpath in the java command line arguments should also be used as classpath for Scala to import packages. But in my test, that did not work

fwiw, that worked on Mac OS X in the simple test I tried. what you saw is maybe:

* something to do with being on Windows?
* something to do with specifying `-classpath` multiple times in the same command line?
* something to do with the `*.jar` wildcard syntax in the classpath?

as I say, just guesses; narrowing it down would take some investigation.

wrn....@gmail.com

unread,
Aug 22, 2015, 1:53:43 AM8/22/15
to ENSIME
Most likely this is a Windows specific issue, and all the causes you listed here might be the cause. But it is still a bug if confirmed regardless the circumstances for it to manifest, which is a suprise to me, as I was expecting Python like maturity, on both Windows and Linux (isn't cross platform a major benefit of JVM based language?).

Sam Halliday

unread,
Aug 22, 2015, 3:43:53 AM8/22/15
to ens...@googlegroups.com

If you think you've found a bug is Scala itself, I suggest you raise that on the Scala users group. If you think you've found a bug in ENSIME, please read the CONTRIBUTING file and send us a fix because it sounds trivial. I still don't fully understand what is wrong because none of what you're describing sounds familiar in the way that ENSIME launches a REPL.

On 22 Aug 2015 6:53 am, <wrn....@gmail.com> wrote:
Most likely this is a Windows specific issue, and all the causes you listed here might be the cause. But it is still a bug if confirmed regardless the circumstances for it to manifest, which is a suprise to me, as I was expecting Python like maturity, on both Windows and Linux (isn't cross platform a major benefit of JVM based language?).

wrn....@gmail.com

unread,
Aug 22, 2015, 11:17:20 AM8/22/15
to ENSIME
I will try to do both. But they are related as part of the needed change on ENSIME is to work around the Scala bug (if confirmed).

I did not do anything special to launch Ensime repl. Did you try running M-x ensime-inf-switch on Windows? If it works for you, please let me know your setup. Thanks.

Reply all
Reply to author
Forward
0 new messages