Set up Scala for NetBeans - Error - scala

I'm interested in the language Scala and would like to test it with NetBeans Can 6.8. I've downloaded Scala 2.8.0 final und unzipped it to my hard drive. Then I installed the Scala plugin for NetBeans and created a first project. Naturally compilation failed with this message:
You must set SCALA_HOME or environment
property and append
"-J-Dscala.home=scalahomepath"
property to the end of "netbeans_default_options" in
NetBeansInstallationPath/etc/netbeans.conf
to point to
Scala installation directory.
I read what the NetBeans Wiki and the Scala website say to the plugin.
I've added a new environment variable $SCALA_HOME that points to D:\Tools\scala-2.8.0.final
I've added $SCALA_HOME\bin to my path variable
I've edited the netbeans.conf file by adding "-J-Dscala.home=D:\Tools\scala-2.8.0.final" to the end of netbeans_default_options
With your great help this error was fixed. However there are two new problems:
Code Completion doesn't work
2.
After creating a Scala Object this
package scalaapplication1
object te {
}
is not accepted. NetBeans complains
that
type ScalaObject is not a member of
package Scala

Strange: the Netbeans Wiki on Scala doesn't mention "scala.home", only the environment variable SCALA_HOME.
So does the tutorial on Scala plugin installation:
After that, you need to make sure Netbeans is launched from a new dos session (one that has registered the new environment variable definition), and is "path-aware" (like this issue 175394, even though it only concerns Unix platform).
DarrenWang mentions in his article the NBModules plugins to more easily manage those options like "-J-Dscala.home = scalahomepath" in the netbeans.conf file.
But it experienced some crashed with the Scala plugin and the latest Netbeans.

Can you read Chinese? hehe, I wrote down something here:
http://www.zeuux.com/group/scalaba/bbs/content/4240/

Related

Why does IntelliJ seem to import my scala libraries twice?

I have just started trying to use Scala with IntelliJ. I created a new project as per the instructions in:
https://docs.scala-lang.org/getting-started-intellij-track/getting-started-with-scala-in-intellij.html
I installed scala 2.12.6 using Homebrew and selected that when creating my new Scala project in IntelliJ.
For some reason, under External Libraries, I have every jar inside the scala installation twice:
I created a hello world and when I try to run it, I get this error:
Error:scalac: Multiple 'scala-library*.jar' files (scala-library.jar, scala-library.jar) in Scala compiler classpath in Scala SDK scala-sdk-2.12.6
However inside the Scala libraries folder there is only one jar of each.
I'm not sure what I'm doing wrong here. I've tried other versions of Scala, but got the same results. I tried to delete one of the jars, and deleted the actual only copy of it and I had to reinstall scala.
#Zapatilla,
Follow this,
Click File --> Project Structure; Select Modules; Select Dependencies
You should see scala-sdk-2.12.6 there. Remove it by selecting it first and then clicking the "-" sign below.
Once done click the "+" button and select "2. Library --> Scala from SDK"; Select the appropriate version and hit Apply;Ok.
This should resolve it.
I just found the problem. When I right click on the library in the project explorer, I saw the paths for each jar file. It seems like in the scala installation by homebrew made in /usr/local/Cellar/scala/<version> there are two folders that contain the same jars:
/usr/local/Cellar/scala/<version>/idea/lib
and
/usr/local/Cellar/scala/<version>/libexec/lib
Since I was importing in IntelliJ this path /usr/local/Cellar/scala/<version>, all jars from both folders were imported, causing the duplication.
Solution is to import just one of those two options. I have now set up IntelliJ to just use as external libraries /usr/local/Cellar/scala/<version>/idea/lib and it seems to work!
I am using windows & intelliJ combination, I faced the same issue since i am new to scala, as usual i was searching in google and spend much time in resolving my issue.
Most of the suggestions are for linux based, please try the below, in my case it worked out.
1) Check your iml file and verify the orderEntry. By default if you download sbt, it would contain 2 set of libraries. I downloaded the SBT version 1.2.7, it by default contain 2 set of libraries. one with 2.12.0 and another with 2.12.7.
2) The project iml file of mine had with scala SDK 2.12.0 which was the reason for my issues, I edited that to change to 2.12.7 which automatically changed the order with 2.12.7 first and solved my issue.
This solved my problem.

How to add Scala Platform to nebeans 8

I'm trying to use NetBeans 8.01 with Scala, and it can't find the "Scala Platform".
I'm using Windows8.1 x64. I follow this tutorial and also I have read this question but doesn't work.
I follow path tools-->Scala Platform and I have error: The specified folder not contain a Scala platform.
I try to add a new Platform but netbeans not find Scala platform.
Finally I try IntelliJ IDEA with scala and it's work.
So wonder if exist bug in netbeans or I must do something else? Can someone straighten me out?
Thank you
I found solution.
I add "-J-Dscala.home=C:\Program Files (x86)\scala" to the NetBeans/etc/netbeans.conf.
Now I can run an scala program.
However if you want to call scala program from java code in netbeans there are two ways
you must create maven project
package scala code to a jar and add this jar to Java project
Open the netbeans.conf file found in Netbeans/etc/
Find the section netbeans_default_options.
Add
-J-Dscala.home="C:\Program Files (x86)\scala"
in this section. Do not forget the " " around the path as spaces cannot be read.

Can't examine variables in scala code in Eclipse

When I debug a Scala application in eclipse I get a dialog with this message on start up: Unable to set breakpoints in Main due to missing line number artifacts.
When I try to examine variables I get this error in the expressions window: " [in Main [in [Working copy] Main.scala [in [in src [in Scala1]]]]] does not exist"
I've tried setting various debug level settings for the Scala compiler including "line" and the highest setting but it doesn't seem to make any difference. I was able to see the contents once after messing with settings but was unable to do again so am wondering if there is a bug to do with bad cached state somewhere.
I am using the Indigo service release of Eclipse with version 2.0.0v2_09 of the Scala plugin.
You should upgrade to the new version of the Scala IDE !
(Strictly) Prior to 3.0.0, the debugger was the Java debugger, with no particular Scala support. But ScalaIDE 3.0.0 shipped with a Scala Debugger that should alleviate the problems you mention, specifically well-positioned breakpoints. You can read the release notes of 3.0.0 describing the debugger.
You should even try the release candidate version of 3.0.1, it contains fixes for the debugger, specifically skipping breakpoints. Try it, and if any issues remain, you can engage the IDE team on the mailing list, or file an issue, or ask another SO question!
You can download the Scala IDE for eclipse with the Scala Worksheet pre-installed from the following URL:
enter link description here
//The URL is from the scala course at coursera
With the Scala Worksheet you can create worksheets and watch the vars at the same time you code

Class not being built using Scala Eclipse plug-in

I'm trying to use the Scala Eclipse plug-in (version 1.1.0, which appears to be the most current) with version 3.7 of Eclipse on Mac OS X 10.6.8. I've copied the "Hello, World" program from a tutorial website. I was able to build the program successfully using the command-line scalac compiler. However, when I attempt to run the project as a Scala application from within Eclipse, I get an error like so:
Exception in thread "main" java.lang.NoClassDefFoundError: de/vogella/scala/first/Hello
with a bunch more stuff following. Looking in the relevant directory structure in my Eclipse workspace directory shows that the associated bin directory is completely empty. However, there are no errors (and indeed no messages of any sort) when I select "Build Project" from the menu.
As far as I can tell, my Eclipse installation is otherwise functional. I can, for instance, successfully build and run Java projects.
Any tips on where to start with troubleshooting would be greatly appreciated. Trying the suggested solutions in the most relevant-seeming existing question didn't work.
EDIT to add: There isn't anything in the Error Log window except this:
System property http.nonProxyHosts has been set to
local|*.local|169.254/16|*.169.254/16 by an external source. This value will be
overwritten using the values from the preferences
which doesn't strike me as terribly relevant. The full text, as copied from the tutorial, of the Hello.scala file, is
package de.vogella.scala.first
object Hello {
def main (args: Array[String]) {
println("Hello, world!")
}
}
and the package the file is a part of is called de.vogella.scala.first.
I followed Kipton Barros' suggestion from the comments, and installed the 2.0.0 beta of the Scala IDE plug-in for Eclipse. While I find it slightly strange that switching from a final release to a beta release resolved the issue, resolve the issue it did.
(Too bad I can't accept a comment as the answer.)
Check if the package declaration in your scala file match the packages in eclipse.

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