Scala terminal launch error: Illegal instruction: 4 - scala

New to Scala and I installed Scala using homebrew. When I type scala in terminal, it is giving me the following error:
$ scala
Welcome to Scala 2.13.7 (OpenJDK 64-Bit Server VM, Java 17.0.1).
Type in expressions for evaluation. Or try :help.
/opt/homebrew/Cellar/scala/2.13.7/libexec/bin/scala: line 25: 53932 Illegal instruction: 4 "$#"
What might be the issue and how can I fix? I am using M1 Mac with Big Sur.

It‘s probably https://github.com/scala/bug/issues/12491, though the error message you're seeing is a little different, which I find puzzling.
Assuming that's the problem, then: Scala 2.13.8 will be out soon (target: January 10) with a fix. In the meantime use 2.13.6, or launch 2.13.7 with -J-Dorg.jline.terminal.jna=false (but this may disable some terminal niceties), or use a 2.13.8 nightly build.

brew upgrade scala
Solved the problem.

Related

sbt runs on command line but not VS code

So I've been trying to run scala on vs code for nearly a week now with no luck. We have been recommended to use sbt to run our programs.
I'm running java version "1.8.0_301" on my build environment.
when running the sbt command on vs code I get project loading failed with this error:
[error] java.io.IOError: java.lang.RuntimeException: /packages cannot be represented as URI
What's weird is that I can run sbt on my command line with no problems!
I'm pretty new to this so any help would be greatly appreciated.
https://imgur.com/l2qzS01 (link to the vs code window after failed loading and scala running on terminal)
cheers!
This is an error that occurs with outdated sbt versions. Upgrade to the latest sbt version and you should be fine.
Unfortunately I don't recall exactly when this was fixed.

Scala: packages cannot be represented as URI

I have openjdk, scala and sbt, all installed via brew. I'm trying to
get setup to work on the scala track on exercism. I'm having no
troubles with Java or anything that uses the JVM like clojure, but
when I try to test my installation of scala by running the test for
the exercism hello example:
$ sbt test
I get a bunch of errors that seem to start with this:
java.io.IOError: java.lang.RuntimeException:
/packages cannot be represented as URI
My installed versions are as follows:
$ java --version
openjdk 13.0.1 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 13.0.1+9, mixed mode, sharing)
$ scala -version
Scala code runner version 2.13.1 --
$ sbt --version
sbt version in this project: 1.3.8
sbt script version: 1.3.8
I've looked and seen this error in a few questions but not seen a way to fix it.
I solved the issue by installing a java version of 1.8 and set JAVA_HOME towards this version.
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home"
I've got the same issue on IntelliJ IDEA and solved it with
Settings > Build, Exec... > Build Tools > sbt > JRE > set to 1.8.
JAVA_HOME has not resolve it in my case
In my case, in Intellij IDEA, I had JAVA_HOME as well as sbt JRE from the previous answer set to 1.8, but I completely forgot about the Project SDK, which was set to an incompatible version.
Ctrl + Alt + Shift + S > Project Settings > Project > Project SDK
Setting this to 1.8 as well as language levels of modules to 8 fixed my issues.
Intellij :
open Settings -> Build, Execution, Deployment -> Scala Compiler -> Scala Compile Server, then change the JDK to the one your project used. This solution solved my problem.
IntelliJ:
Go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> sbt
Make sure Use sbt shell for build is checked
I found this S/O answer solves my issue:
This is a Scala compiler bug. Please upgrade to the latest Scala point release, 2.12.16.

Error when open eclipse - MAC

I have installed eclipse on my iMac and when I try to open it, it gives me this error:
Failed to find a Main Class in
"/Applications/Eclipse.app/Contents/MacOS//../Eclipse/ plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar".
On my MacBook Pro, everything works fine, but I have done nothing different.
I have checked other posts, but most of them refer to a windows OS. There was an answer which said that it can just open when everything is in an English folder and this is true for me!
Thanking you in advance!
I came across this error after installing Eclipse PDT.
Open your terminal and run the version command: java -version.
If your java version is below 1.8, you will have to update your Java
Runtime Environment to at least 1.8.0 by installing an updated JDK
here.
Then re-run the java version command and your version
should be updated.
You should now be able to install and run
Eclipse.
I have the same issue, but on my MacBookPro. I first installed eclipse Photon, which when starting up prompted me to install Java 6, which I did from https://support.apple.com/kb/DL1572?locale=en_US
Then I also installed the latest JRE (jre-8u171-macosx-x64 as of yesterday). When running eclipse again I started getting this error. Then I tried to run from the command line, and got this error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/equinox/launcher/Main : Unsupported major.minor version 51.0
When googling that, the answers said that the reason for that is that the Oracle installer does not update the symlink in /usr/bin, which seemed to be confirmed by the fact that running java -version returned this:
java -version
java version "1.6.0_65"
The solutions I found for that were not feasible in MacOS starting in version El Capitan, and I am on High Sierra, so I followed the instructions in this post to fix that, and it worked, now I get:
java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
After all of this, however, I get the same "Failed to find a Main Class" error on the dialog as reported initially here, and the same "UnsupportedClassVersionError" on the CLI that I had when the system was still on java 6, so now I am still stuck and out of ideas.
EDIT: FIXED IT!!
I kept thinking that the problem was the java version, it was somehow still using java 6 (which I had installed due to the initial prompt).
So I followed the instructions here to remove what I had installed for the alleged java 6 issue. Then I found this post in the eclipse forums, which stated at the end (comment added by Eric Rizzo on Tue, 14 February 2017 21:56) that this is not an Eclipse message, but rather an OS message, and that one should NOT do that as apple messed things up with that patch. And then it goes to explain that one should install java 8 JDK (NOT just the JRE as I had done). Once I removed Java 6 and installed the full java 8 JDK, it ran fine :)
You can edit the eclipse.ini with your vm configuration in the beginning of the file
-vm
/yourJvmPath/jdk-12.0.1.jdk/bin/java
cat /Applications/Eclipse.app/Contents/Eclipse/eclipse.ini
-vm
/Users/SomeUser/jdk-12.0.1.jdk/bin/java
-startup
../Eclipse/plugins/org.eclipse.equinox.launcher_1.5.400.v20190515-0925.jar
--launcher.library
../Eclipse/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.1000.v20190125-2016
PD. It works with ApacheDirectoryStudio for MAC
This one works for me with MAC OS Mojave.
You can download the Java SE Development Kit 8u221 for mac from the below link.
jdk-8u221-macosx-x64.dmg
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Fixing scala compiler and library in IntelliJ 13

I have intellij 13 ultimate.
I had scala 2.10.3 installed, and recently upgraded to 2.11 using homebrew.
When I open a sbt project, it may have a different scala version and if it does then it starts to download etc.
Will IntelliJ automatically use the correct compiler for a sbt project once it finishes downloading everything?
I currently have these errors which I'm not sure how to fix:

MTurk Command Line Tools Error: Bad version number in .class file

I am using the Mechanical Turk command line tools on Windows. When I try to run a command (e.g., getBalance, createQualificationType), I always get the following error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
Any clues as to what I could look at to fix this would be greatly appreciated!!
I have tried updating my key and secret key to no avail.
Note: I can get help for the commands by using -help, but I cannot run the commands themselves.
This error occurs whether I am running either JRE 1.5.0_06-b05, 1.5.0_22-b03, or 1.7.0_17-b02. The command line tools documentation states, "You must have the Java JRE 1.5.X (JRE 5). The Command Line Tools are not 100% compatible with JRE 6."
Since I am using the version of the command line tools packaged with JRE, I have also uninstalled my JRE. I get the same error.
UnsupportedClassVersionError means that you are trying to use a Java class that was compiled with a newer JDK on an older Java runtime environment. For example, you have a class that was compiled with JDK 7, and you are trying to use it on a Java 6 or older runtime environment.
Java is downwards compatible; newer Java runtime environments can run Java classes compiled with older versions without modifications, but not the other way around.
Check with what version the class you are trying to use was compiled, and use a Java runtime environment with the same version or newer to run the class.
You can check your Java runtime environment and JDK versions with:
java -version
javac -version
Apparently, the CLT installer installs a JRE that is too old to run the tools included in the installer. Seems like a serious bug (certainly annoying).
You can fix by installing and using a more recent JDK.
This post contains instructions on how to do so:
https://forums.aws.amazon.com/message.jspa?messageID=388586#388585