Can't run java when trying to download Scala - scala

I'm working with a Scala project and am trying to get IntelliJ to work with it. (If it makes a difference, I've gotten it to work before. But my machine died and had to be replaced, and this is the first time I've tried to use Scala since reinstalling IntelliJ on the new machine.) The machine is running Linux.
I've gotten the banner that says "No Scala SDK in module", and I selected "Setup Scala SDK"; Create; Download; Version 2.11.11; OK. But I get the message
Cannot run program "java" (in directory "/tmp/sbt-project"): error=2,
No such file or directory
Why is it looking in that directory (which does not exist on my machine)? It's possible there are some settings that got copied over from my previous machine. If so, where would I find and fix the setting?
How do I get past this problem?
Note: In a desperate attempt to work around the error, I created /tmp/sbt-project and symlinked the Java binaries into it. When I tried again, I got the same error except it said in directory "/tmp/sbt-project1". I tried creating /tmp/sbt-project1 as a symlink, and when I retried, it said in directory "/tmp/sbt-project2". What's going on?

In short: I have no idea why you and I both experienced this problem, but these steps remedied the situation for my particular case (no guarantees but maybe it will help you too)
Close Intellij
Likely in your home directory, backup and remove the .Idea* directory containing your personal settings
Open Intellij and at the welcome screen choose Do not import settings
Using the guided installation, ensure the "Featured" plugin, Scala, is installed
Reopen your project and when you setup the Scala SDK, miraculously a pre-existing version of Scala SDK should exist from the "Ivy" repository (I tested this on a fresh VM of Lubuntu)
After selecting the (likely outdated) Scala SDK, again go to Project Settings and under Global Libraries click the + symbol to add the latest Scala SDK.
Miraculously once again, you will see now both the SDK version from before and the latest version of Scala - choose that one and done!
Notes:
Before running those above steps, I tried the same things you did on the VM, possibly caching install versions I wasn't even aware of that later became available once I resetup Intellij.
The reason I suspect this worked is because I thought I would save myself time by copying the .Idea* directory from a different machine and using that - many paths were different! So likely I just disabled features with broken paths from my other machine
Even though I never needed to press the "Download" button, if I do I still get that same error! So I guess all this did was bypass manually downloading the SDK like you had to do...
My setup:
OS: Lubuntu-16.04.3-lts
Intellij Version:
IntelliJ IDEA 2018.1.4 (Community Edition)
Build #IC-181.5087.20, built on May 16, 2018
JRE: 1.8.0_152-release-1136-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-43-generic
echo $PATH
/home/e/tools/jdk1.8.0_121/bin:/home/e/bin:/home/e/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

I met the same problem when installing Scala by IntelliJ.
You can choose to install Scala mannually.
For example, install Scala follow this tutorial: https://www.vultr.com/docs/how-to-install-scala-on-centos-7
Then use Browse when selecting Scala SDK. Choose your directory, e.g. /usr/share/scala/
You can use Scala in IntelliJ now.

Related

Why can't IntelliJ scala plugin pickup my dependencies?

I am using intellij 11 ultimate, using the scala plugin.
Most of my code has red highlights everywhere, meaning IntelliJ cannot properly resolve the keywords.
For example, I added the amazon aws depenency (using sbt) and 1/2 my code is red, and intellisence doesn't work either.
Note: This is happening for many many libraries I am using, and it is a real pain. I am building using the terminal using the sbt command also.
Is there something I am doing wrong? Or is it just a fact of live using scala with intellij?
Update:
I do see this message sometimes:
File '/path/to/app/web/built.sbt' seems to be SBT build file, but there is no external project related to it. Import the corresponing project?
"File -> Invalidate Caches -> Invalidate and Restart" often helps to prevent IntelliJ from showing non-existing Scala errors.
I have no IntelliJ 11, so I do not know if this exists in your Intellij version.

Scala Netbeans 8.1 installation configuration

I was able to make some progress in getting Scala running on the Netbeans IDE. I am stuck with what looks like an error finding file sh.exe. I have found this file in my git directory but I have no idea where it should be in a Scala configuration. Here is the beginning of the error message, is this familiar to someone?
SBT -Completion: -Exit: exit -Help: help.
sbt-launch=C:\Users\William\AppData\Roaming\NetBeans\8.0\modules\ext\org.netbeans.libs.sbt\1\org-scala-sbt\sbt-launch.jar
[ERROR] Failed to construct terminal; falling back to unsupported
java.io.IOException: Cannot run program "sh": CreateProcess error=2,
The system cannot find the file specified at
java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
I had this problem with the newest version of NetBeans Plugin for Scala within Windows OS during use of the Scala SBT plugin. Cygwin should solve the problem (after instalation don't forget to set the path/to/cygwin/bin in the Windows path variable).
When I down load the small installation program and start the install I am presented with a large category of files without one being Scala. Do you know which packages need to be installed or a link to a document?
By continuing the install without adding any additional package and then adding the path as was suggested I was able to compile a scala project in the Netbeans 8.0.2 IDE.

Why does IDEA report errors for build.sbt in a new sbt project?

I'm running IntelliJ 13.1.5 community edition. I've got JDK, Scala, SBT installed. The JAVA_HOME, JDK_HOME, SCALA_HOME and SBT_HOME variables are set. If I create a new SBT project, after initial sbt refresh, I get this:
The thing compiles and runs fine, even if I add dependencies, but the file itself shows tonnes of errors. F4 settings show empty SBT module stuff:
I then installed https://github.com/mpeltonen/sbt-idea and ran sbt gen-idea in the project folder. This created a bunch of files, and reloading the project, the reds in the sbt file went away.
This is on my laptop. However, on my work machine, simply creating a new project works fine, and the sbt file isn't filled with red. Can't seem to figure out how that machine's different. Any pointers on how to resolve this annoying issue?
In case IntelliJ IDEA struggles a bit with caching, try the first and if still not working the second should definitely do the trick:
File -> Invalidate cache and restart
Close IDEA, delete .idea, re-import your project
I was also getting highlighted errors in all of the build.sbt file.
What fixed it was to select to Download "Sources for SBT and plugins" in the Import Project from SBT window.
Please, check if you added the “scala-library*.jar” to Scala compiler library
This link might be helpful:
http://blog.jetbrains.com/scala/2010/09/02/project-configuration-explained/
If you are using windows or linux, please also see:
http://confluence.jetbrains.com/display/SCA/Setting+up+Scala+plugin+project+in+IntelliJ+IDEA
Update on 2020, Apr
This works for scala 2.13 and Intellij 2020.1 when:
sbt files has error
project structure is wrong
Reason is 'External libraries' from sbt is not loading for IDE.
To do so, similar to old version: https://www.lagomframework.com/documentation/1.6.x/java/IntellijSbtJava.html
1. rm -rf .ida
2. Click Menu item: Open... to pick the project directory
If not working, I assume you need to setup Global SDK for intellij by
cmd+; and pick the path of scala.
In case of mac,
brew install scala normally echo out the path /usr/local/opt/scala/idea
Let ide browse to this path by holding cmd+shift+G to open path.
IDE should find the path like /usr/local/Cellar/scala/2.13.1/idea/lib/scala-library.jar and scala-compiler.jar and scala-reflect.jar
There might be better way to do the global scala setting though.

GWT compile hangs

I created a Google Web Toolkit project in Eclipse (Indigo, GWT 2.4, Linux Ubuntu), made some changes (mainly, renamed the default module and added a new module), then clicked "GWT Compile", and then nothing happened - the compilation just hanged forever. There is no output; the progress bar at the bottom right shows "0%".
When I use "loglevel=all", I get a single line of output "Checking for updates" and then it hangs.
I tried deleting the cache - no change.
I tried creating a new project and copying the source files - no change.
With the help of this link: http://comments.gmane.org/gmane.org.google.gwt/70561 I added "-XdisableUpdateCheck" to the compiler; now the compile completes, but, when I try to run in development mode ("Run as -> Web application") it says "Development mode is loading..." and hangs.
I don't know even how to start debugging this. Please give me some hint!
I faced the similar issue. Here is my sequence of events for it:
Checked out the GWT project from the SVN --> tried to Google-GWT Compile --> gave entry point modules --> my log level was info and output style Obfoscated -->Hit compile.. Nothing happens except the progress bar stuck at 0%.
Tried to google and find out the solution in multiple ways but couldn't get the proper answer.
One trick worked --> I deleted the project from the eclipse workspace and re-imported it from the disk as an existing project. GWT compile worked this time. :)
Why it worked? --> When we delete the project from eclipse workspace all the libraries associated with that project get unbound and removed from the classpath. When you again import the same project and try to compile GWT before adding the required libraries to the classpath it will works. The real conflict is with GWT libraries and JBoss 5.0 libraries. There looks like some plain bug in GWT2.4 which they need to resolve. In the classpath if you precede the jboss and Web App libraries prior to GWT library the compile gets stuck.
If you face the similar issue, remove jboss and web app libraries from the classpath and compile GWT module and then add those removed libraries sothat the JAva source from your project gets compiled. Good luck!
I was having the same problem after working through this tutorial: http://www.javacodegeeks.com/2010/12/securing-gwt-apps-with-spring-security.html
In the end it was a dodgy external JAR that I added to my build path (the spring-context one mentioned in the tutorial). I grabbed another copy of it and all is good now.
Here is the FIX for this one as we cannot continue with this whole business of taking the jBoss library in and out every time we need to compile GWT.
The problem is that com.google.gwt.dev.javac.JdtCompiler.getCompilerOptions
(JdtCompiler.java) is referring to CompilerOptions which, as fate would have it, is referencing to the implementation in jasper-jdt.jar (situated in jboss library) instead of gwt specific implementation. Get ride of this jasper-jdt.jar from jBoss library and you should be all set. Don't worry if you absolutely need any of the classes from jasper-jdt.jar; there are tons of alternative Jasper jars who can fulfill your need other than this one.
try this: right click->google->gwt compile->click advance (bottom) and
In the Additional compiler argument add this:
-XdisableUpdateCheck
Giving option -XdisableUpdateCheck to GWT Compiler solves the deadlock problem for me. Thanks for the hint.
Used GWT 2.5.0 with java :
$ java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)
$ cat /etc/issue
Fedora release 18 (Spherical Cow)
Kernel \r on an \m (\l)
$ uname -a
Linux myhostname 3.9.4-200.fc18.x86_64 #1 SMP Fri May 24 20:10:49 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
I could solve the problem by setting the optimization level (console Argument -optimize 8 to 8, which means optimize the code at most 8 times. Default is level 9 resulting in optimizing until nothing changes anymore. It seems there are a few cases where this results in an endless loop.
Also see this issue on GitHub:
https://github.com/gwtproject/gwt/issues/9452#issuecomment-259088434
Old question, but today a colleage of mine was just running into this issue, too. It turned out that he was using classes from client packages (both own classes and ...client.rpc.IsSerializable) within the shared package of his project.
As a result the GWT build froze at compiling permutation 0. I assume that it got trapped within an endless loop between compiling shared and client classes.
Removing all usages of client classes from shared classes helped.

How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?

I recently gave up trying to use Scala in Eclipse (basic stuff like completion doesn't work). So now I'm trying IntelliJ. I'm not getting very far.
I've been able to edit programs (within syntax highlighting and completion... yay!). But I'm unable to run even the simplest "Hello World". This was the original error:
Scala signature Predef has wrong version
Expected 5.0
found: 4.1 in .... scala-library.jar
But that was yesterday with IDEA 9.0.1. See below...
UPDATE
Today I uninstalled IntelliJ 9.0.1, and installed 9.0.2 Early Availability, with the 4/14 stable version of the Scala plug-in.
Then I setup a project from scratch through the wizards:
new project from scratch
JDK is 1.6.u20
accept the default (project) instead of global / module
accept the download of Scala 2.8.0beta1 into project's lib folder
Created a new class:
object hello {
def main(args: Array[String]) {
println("hello: " + args);
}
}
For my efforts, I now have a brand-new error :)
Here it is:
Scalac internal error: class java.lang.ClassNotFoundException [java.net.URLClassLoader$1.run(URLClassLoader.java:202), java.security.AccessController.doPrivileged(Native Method), java.net.URLClassLoader.findClass(URLClassLoader.java:190), java.lang.ClassLoader.loadClass(ClassLoader.java:307), sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301), java.lang.ClassLoader.loadClass(ClassLoader.java:248), java.lang.Class.forName0(Native Method), java.lang.Class.forName(Class.java:169), org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main(ScalacRunner.java:72)]
FINAL UPDATE
I uninstalled 9.0.2 EA and reinstalled 9.0.1, but this time went with the 2.7.3 version of Scala rather than the default 2.7.6, because 2.7.3 is the one shown in the screen-shots at the IntelliJ website (I guess the screen-shots prove that they actually tested this version!). Now everything works!!!
I have encountered the same scalac error when trying to run a Scala project in Intellij Idea 9.0.2 and I've managed to find a solution by chance :). These are the steps I took in creating the project and running it.
I have created a Scala project in Intellij Idea 9.0.2 final (it was released today). I have installed the Scala plugin, restarted the IDE and created a new Scala project (with the name "TestScala") with scala-2.8.0.Beta1 as project library. Once the project is created and the scala libraries downloaded, I have created a Test.scala file with the following content:
object Test {
def main(args:Array[String]){
println("hello")
}
}
After that, I created a launch configuration ("Edit Configurations"), choosing the "Application" template. I set as main class Test and choose the project name ("TestScala") in the "Use classpath and JDK of module" combo box. When I run the configuration I get the same error as you reported ("Scalac internal error: class java.lang.ClassNotFoundException") .
Now comes the freaky part :). I right click on the project, choose "Module Settings", have a look on all settings but I don't change anything . Click "apply" and "ok", try to run configuration again and it works :) .
I use Intellij Idea 9.0.2 the final release (build 95-66); Ubuntu 9.10 and JDK 1.6.0_18. I also have to mention that I had a JDK configured in Intellij, otherwise there is an extra step to configure it.
UPDATE:
When checking the setting of the module, one needs to click on the Module->Scala and Facets->Scala (expand it and click on Scala(ProjectName)) . Both of these settings are about the scala compiler and scala library location. I would guess these values are not properly set when the project is created but are saved once the user touches them and saves the settings.
To answer your question, it's difficult to get a working IDE for Scala for two reasons:
(a) Scala is only just beginning to reach a wide audience and
(b) due to (a), there is no business case for spending time on a Scala IDE.
Also, if you are old enough to cast your mind back and young enough to still remember, you would know that for the first five or more years of Java, we were stuck with okay-ish tools like JBuilder that did little more than compile your code when you said so - no error highlighting, no auto-importing, and the word refactoring didn't even exist. If you want to pioneer, you need to be prepared to cut some of the road yourself, or at least bush-bash.
I know it won't help you, but I have successfully used IDEA for Scala on Linux, Mac and Windows. I typically have the Scala SDK installed somewhere locally and point IDEA at that rather than using the 'download' option.
Presently, I am mostly using an EAP version of IDEA 9 on Mac OS X with Scala 2.8.0.Beta1-RC5 and it's working well (except that fsc doesn't seem to worked with mixed sources).
You could try your luck over at the IDEA Scala Plugin Discussion Forum, though I haven't had a great lot of responses to my own postings there.
Installing the plug-in is prerequisite one.
The next thing you should do is define a library (global or project-specific; I use global) that holds the Scala library and compiler JAR files (at a minimum, that's scala-compiler.jar and scala-library.jar). Adding source JARs and a documentation JAR or URLs is a good idea, too. Then make this library a dependency of any modules in your project that include Scala code.
Lastly, find the Scala facets in those modules and de-select both check-boxes there.
I just did a fresh install and had exactly this same problem myself.
It turned out that, because I had created the file in the root package, IDEA had added a package statement at the top with naming a package. I assume that this then got compiled as "package object Main" - valid syntax in 2.8? Anyway, I deleted the line that said package and it all worked fine.
I had the same problem yesterday while trying to set it up. Solution is pretty simple, you just have to set scala somewhere in project settings.
You are mixing code compiled with two different Scala versions.
I use Netbeans to write scala programs. So far it works very well with my codes. You can try the plugin here: http://wiki.netbeans.org/Scala68v1.
I was getting this error and also had to right click on the project and "Open Module Settings". However, it was more than just hitting apply. I had to make sure that my Content Root was correct for each project. For some reason, there were some incorrect Source and Test Folders.
My project uses maven as the main build tool and importing the project into Intellij is probably what created these incorrect settings.
I had similar problem, following this blog post instructions solved the problem for me