I'm a newbie in scala. I recently started using netbeans for writing scala programs.I have installed scala version 2.11.0.400 and its plugins for netbeans.When I try to compile my scala code:-
package scalaapplication2
object Main {
def main(args: Array[String]): Unit=
{
println("Hello, world!")
}
}
I get the following compilation error even after setting the path variables:-
Compiling 1 source file to C:\Users\Nitin\Documents\NetBeansProject\ScalaApplication2\build\classes
C:\Users\Nitin\Documents\NetBeansProjects\ScalaApplication2\nbproject\build- impl.xml:423:
The following error occurred while executing this line:
C:\Users\Nitin\Documents\NetBeansProjects\ScalaApplication2\nbproject\build-impl.xml:238: bad option: '-make:transitive'
Why is it so?
Removing '-make:transitive' from the scalac addparams option (Files view > ScalaApplication > nbproject > build-impl.xml) worked for me.
Related
I am getting the following error when compiling a Hello World Program in Netbeans.
C:\Users\Norman\Documents\NetBeansProjects\LambdaCollectionExamples\ScalaApplication2\nbproject\build-impl.xml:238: bad option: '-make:transitive'.
This is the xml file:-
<scalac addparams="-make:transitive -dependencyfile "${basedir}/${build.dir}/.scala_dependencies" #{addparams}"
deprecation="${scalac.deprecation}"
destdir="#{destdir}"
encoding="${source.encoding}" excludes="#{excludes}"
extdirs="#{extdirs}"
force="yes"
fork="true"
includes="#{includes}"
sourcepath="#{sourcepath}"
srcdir="#{srcdir}"
target="jvm-${javac.target}"
unchecked="${scalac.unchecked}">
This is the program
package scalaapplication2
object Main {
/**
* #param args the command line arguments
*/
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
Scala 2.11.2 was giving me such errors. Download Scala 2.10.4 binaries for your system should resolve it.
ant -f C:\\Users\\wayne\\Documents\\NetBeansProjects\\ScalaApplication2 run
init:
deps-jar:
Compiling 1 source file to C:\Users\wayne\Documents\NetBeansProjects\ScalaApplication2\build\classes
Recompiling 1 files
warning: there were 1 deprecation warning(s); re-run with -deprecation for details
one warning found
compile:
run:
Hello, world!
BUILD SUCCESSFUL (total time: 3 seconds)
I am trying to use JOGL with Scala in Eclipse, but being a JOGL/Scala neophyte, have run into some dependency errors which I cannot make any heads or tails of. Googling hasn't returned much of anything useful.
I have set up a Java JOGL project as per
Setting_up_a_JogAmp_project_in_your_favorite_IDE.
Compiling the following Java class in a Java project that depends on the above project
import javax.media.opengl.GLProfile;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.awt.GLCanvas;
public class Game {
public static void main(String[] args) {
GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(glp);
GLCanvas canvas = new GLCanvas(caps);
System.out.println("Hello World");
}
}
works, and outputs Hello World as expected.
However, making a Scala project and trying to use the JOGL project as follows
import javax.media.opengl.GLProfile;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.awt.GLCanvas;
object Game {
def main (args: Array[String]): Unit = {
val glp = GLProfile.getDefault();
val caps = new GLCapabilities(glp);
val canvas : GLCanvas = new GLCanvas(caps);
System.out.println("Hello World");
}
}
won't even compile, as Eclipse informs me of the following errors:
error while loading CapabilitiesImmutable, Missing dependency 'class com.jogamp.common.type.WriteCloneable', required by G:\Eclipse\workspace\JOGL\jogl-all.jar(javax/media/nativewindow/CapabilitiesImmutable.class) Scala JOGL Unknown Scala Problem
error while loading GLCanvas, Missing dependency 'class com.jogamp.common.util.locks.RecursiveLock', required by G:\Eclipse\workspace\JOGL\jogl-all.jar(javax/media/opengl/awt/GLCanvas.class) Scala JOGL Unknown Scala Problem
error while loading GLContext, Missing dependency 'class
com.jogamp.common.util.locks.RecursiveLock', required by G:\Eclipse\workspace\JOGL\jogl-all.jar(javax/media/opengl/GLContext.class) Scala JOGL Unknown Scala Problem
Removing the lines pertaining to GLCapabilities and GLCanvas, giving
object Game {
def main (args: Array[String]): Unit = {
val glp = GLProfile.getDefault();
System.out.println("Hello World");
}
}
does compile and print Hello World.
My questions are - Why doesn't the Scala code work, and what can I do to fix it? Am I doing some crazy voodoo mixing up JOGL and Scala code that I shouldn't be doing? Did I forget to add some dependencies?
Version Information
Eclipse: (Version: Juno Release Build id: 20120614-1722)
Scala IDE for Eclipse: (Version: 2.1.0.nightly-2_09-201208290312-cc63a95)
(Provider: scala-ide.org)
JOGL as part of JOGAMP Release 2.0-rc10
Edit:
Ok, adding the gluegen-rt.jar and jogl.jar libraries to the build path in the Scala project itself solves this issue (I can't believe I didn't think of doing that first .. ). I'm still not exactly sure what I was doing wrong though.
Just for reference, in one of my JOGL SBT projects, I needed to add:
gluegen-rt.jar
gluegen-rt-natives-.jar
jogl-all-2.0-rc9.jar
jogl-all-2.0-rc9-natives-.jar
to the list of dependencies in order for this to work. My guess is that you have to include these on the build path in Eclipse.
These are available from this repository: http://jogamp.org/deployment/maven
When I run my Scala hello world application, like
package pack
object App {
def main(args: Array[String]) {
println("Hello, world!")
}
on Idea 10.0.3, I get compile errors
'App' to
D:\prog\java2\scala3\out\production\scala3\pack\App.class
(The filename, directory name, or
volume label syntax is incorrect)
'App' to
D:\prog\java2\scala3\out\production\scala3\pack\App$.class
(The filename, directory name, or
volume label syntax is incorrect)
How can I deal with it?
This is an Intellij bug. See bug SCL-3185 in the jetbrains tracking for pointers to release candidate code fixing it.
I'm just learning scala, and I wrote the "hello,world" program like this:
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
I saved it to a file named "helloworld.scala"
Now I run it in the console:
scala helloworld.scala
But nothing outputed. I thought it will output "Hello, world". Why?
PS
If I modify the content to:
println("Hello, world")
and run again, it will output "hello,world".
if you want to run your code as a script (by using scala helloworld.scala) you have to tell scala where your main method is by adding the line
HelloWorld.main(args)
to your code
the second option you have is compiling the script by using scalac helloworld.scala
and then calling the compiled version of your class using scala HelloWorld
You have two options.
Compile and Run:
As in Java you should have a main-method as a starting point of you application. This needs to be compiled with scalac. After that the compiled class file can be started with scala ClassName
scalac helloworld.scala
scala HelloWorld
Script:
If you have a small script only, you can directly write code into a file and run it with the scala command. Then the content of that file will be wrapped automagically in a main-method.
// hello.scala, only containing this:
println("Hello, world!")
then run it:
scala hello.scala
Anyway I would recomment to compile and run. There are some things, that are not possible in a "Scalascript", which I do not remember right now.
I installed the scala plugin on my netbeans and followed the instruction of this page:
http://wiki.netbeans.org/Scala68v1#Scala_Plugins_for_NetBeans_6.8_v1.x_.28RC2.29
but after it completed correctly step by step, when I make an empty project (Hello world!), the project has an error!
The empty project is here:
package scalaapplication1
object Main {
/**
* #param args the command line arguments
*/
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
and the console error report is:
...\NetBeansProjects\ScalaApplication2\nbproject\build-impl.xml:403: The following error occurred while executing this line:
...\NetBeansProjects\ScalaApplication2\nbproject\build-impl.xml:236: scalac doesn't support the "fork" attribute
Is there any suggestion about it?!
I had the same problem with Scala 2.7.7. After installing 2.8.0.RC1 it worked fine.
Henri