Posts tagged spacemacs

Setting JAVA_HOME for SBT inside Emacs GUI

:: scala, spacemacs

Is your terminal SBT and your Emacs (or Spacemacs) SBT giving you different results? More confusingly, is SBT doing the correct thing from inside Emacs if Emacs is started from the terminal and not as a GUI application?

This can be caused by Emacs producing its own environment if started as a GUI application! (And you thought all environments were created equal, out of .bashrc or whatever … Nope.)

This new env that Emacs creates for itself is based on … magic, I guess.

In any case, it does not necessarily respect the JAVA_HOME that you carefully set in your normal (terminal) environment.

In order to correct this, add to your init.el (or dotspacemacs/user-init in .spacemacs):

(setenv "JAVA_HOME"
        "/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/")

or whatever it is that JAVA_HOME should point to.

As an alternative, you can set this variable per project by adding a file .sbtopts in the project root with the following:

-java-home /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/

Ensime server crashed by wrong JAR

:: scala, ensime, spacemacs

If you have a dodgy source jar file, it will probably blow up the ensime server with java.util.zip.ZipException: error in opening zip file. The solution offered in the project’s Github issue is to delete your local copy of the bad file and add it to the list of excluded classifiers in ivy (i.e. ~/.ivy2/exclude_classifiers), and report the file to the nexus hosts to have it deleted.

Mine is a bit longer …

Debug Scala with Spacemacs

:: scala, spacemacs

The documentation about debugging in ENSIME was a bit confusing to me. Here are my notes on how to start debugging an (sbt-based) Scala project from Emacs (Spacemacs):

  1. Launch the debugger from the sbt console first. Use the sbt-mode shell. I don’t really know if this works launching SBT on a terminal not running under Emacs. Use ensimeTestOnlyDebug if you are running a test, otherwise use ensimeRunDebug for an implementation class.

    > ensimeTestOnlyDebug com.company.division.squad.project.package.TestClass
    ...
    Listening for transport dt_socket at address: 5005
  2. Set a breakpoint in a source code line by moving your cursor to that line and using , d b

  3. Attach to the debugger by using , d A. The first time, you will need to specify Host (localhost) and Port (the number in the Listening for transport ... line above)

  4. When (if) the debugger hits the line where your breakpoint is set, the Emacs cursor will jump to that position, and you can start using other debugging commands (, d n, , d i, etc …)