I'm trying to run a very simple hello world Scala program in IntelliJ IDEA on Mac without using the Scala console configuration. I have followed these steps to largely get started, but I didn't set up the debugger outlined there. There isn't a default run configuration enabled, but I can right-click on my source file and select "Scala Console," as we can see here:
Is there a way to select or edit my configurations to make it so I don't have to use the console? Below are the available configurations.
I simply want there to be a way to run my Scala code and see the generated output in the provided console, which Scala Console isn't doing. Thanks for your time.
Lab6 should be an object, not a class.
This will allow you to run it as a main method
Related
is there a way in vscode with metals scala plugin, run specific test scenario ?
Like in IntelliJ ?
If you mean specific test clause in say a scalatest class, I'm pretty sure the answer is "no".
Workaround could be to add a launch configuration and pass args to just run the test you want with -z: https://scalameta.org/metals/docs/editors/vscode.html#via-a-launchjson-configuration
Or just ignore-tag the others.
I'm using Scala 2.11.8 and Spark 2.1.0. I'm totally new to Scala.
Is there a simple way to add a single line breakpoint, similar to Python:
import pdb; pdb.set_trace()
where I'll be dropped into a Scala shell and I can inspect what's going on at that line of execution in the script? (I'd settle for just the end of the script, too...)
I'm currently starting my scripts like so:
$SPARK_HOME/bin/spark-submit --class "MyClassName" --master local target/scala-2.11/my-class-name_2.11-1.0.jar
Is there a way to do this? Would help debugging immensely.
EDIT: The solutions in this other SO post were not very helpful / required lots of boilerplate + didn't work.
I would recommend one of the following two options:
Remote debugging & IntelliJ Idea's "evaluate expression"
The basic idea here is that you debug your app like you would if it was just an ordinary piece of code debugged from within your IDE. The Run->Evaluate expression function allows you to prototype code and you can use most of the debugger's usual variable displays, step (over) etc functionality. However, since you're not running the application from within your IDE, you need to:
Setup the IDE for remote debugging, and
Supply the application with the correct Java options for remote debugging.
For 1, go to Run->Edit configurations, hit the + button in the top right hand corner, select remote, and copy the content of the text field under Command line arguments for running remote JVM (official help).
For 2, you can use the SPARK_SUBMIT_OPTS environment variable to pass those JVM options, e.g.:
SPARK_SUBMIT_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" \
$SPARK_HOME/bin/spark-submit --class Main --master "spark://127.0.0.1:7077" \
./path/to/foo-assembly-1.0.0.jar
Now you can hit the debug button, and set breakpoints etc.
Apache Zeppelin
If you're writing more script-style Scala, you may find it helpful to write it in a Zeppelin Spark Scala interpreter. While it's more like Jupyter/IPython notebooks/the ipython shell than (i)pdb, this does allow you to inspect what's going on at runtime. This will also allow you to graph your data etc. I'd start with these docs.
Caveat
I think the above will only allow debugging code running on the Driver node, not on the Worker nodes (which run your actual map, reduce etc functions). If you for example set a breakpoint inside an anonymous function inside myDataFrame.map{ ... }, it probably won't be hit, since that's executed on some worker node. However, with e.g. myDataFrame.head and the evaluate expression functionality I've been able to fulfil most of my debugging needs. Having said that, I've not tried to specifically pass Java options to executors, so perhaps it's possible (but probably tedious) to get it work.
I'm trying to configure Scala Debuger.
I have specs2 tests:
#RunWith(classOf[JUnitRunner])
class DictionaryTest extends Specification { ...
I've downloaded preconfigured default scala-ide.
Turn on scala debugger by default like was said on the image (2nd slide). Restart eclipse.
Put breakpoint in my specs2 tests, but when start debugger still see java-like stack-traces when the code reaches the breakpoint (not like on 3rd slide).
Q: Are there some addition steps I should perform to start using/testingscala-debugger ?
Edit: why my screen is different than doc's screenshot. It seems Scala debugger was not On? At least I was hoping to see word 'Scala Display'
Unfortunately, your probably hit a known limitation. Currently, the new debugger is available for the Scala launcher, but not for the JUnit launcher. Here is the relevant ticket.
You could work around it if you configured the test runner to wait for a remote debugger connection, and then connect the scala debugger as described here
Eclipse uses console view as read-only.
How can I type command in console view? Is it possible? E.g: ls, mvn install...
Edited:
Thanks Ben and Kelly.
I understand I can interact with Eclipse's console when my application is running. However, I meant I want an embedded console as like as the one in Kate, Dolphin (press F4 in Dolphin)... So I can use bash script in Eclipse's console. Is that possible? Or is there a plugin for that? I have googled but perhaps my keywords were not right...
Edited
Edward has found duplicate question here: Is there an Eclipse plugin to run system shell in the Console?
And it was answered :-)
I don't know how to mark this one as solved. So I place message here, I got the answer.
Edited
But it is not useful. It doesn't have auto complete feature, when I need to type a long file name, or want a hint for a forgotten name,... it is worst :-(
When the console is waiting for input it shows a green prompt that allows you type.
You can test it out by making a simple console application that reads from standard input.
You are trying to think of the Eclipse console as if it were connected to a command-line process. It is actually connected to the JVM used to execute your Java code. Thus, it only shows output that your program sends to System.out and conversely only is available for input if the Java code you are running is requesting input from System.in.
A decent exercise would be to write a small Java program that redirects the input and output to a child process of your favorite shell, for example: http://www.devdaily.com/java/edu/pj/pj010016
The Eclipse Console view is used for communicating with an executed program (typically Java, or similar). If you want to use it as a console, as mentioned in the comment under #Ben S's answer, the Target Management Eclipse project provides a view that can be used for that reason. I don't have it installed right now, so I cannot tell you the required plug-in/view name, but I have used it to connect to the local computer and works.
I developed a simple scala app that uses casbah to query the DB for the command line argument passed to it. For example
$ querydb.scala execution 10
it will run a casbah query to find 10 records matching execution in mongo. Now i have two questions.
1) How do i test this in my local. If i click execute in intellij it is just running the program, i am not able to pass command line arguments to my program.
2) How do i deploy it to run on my server, it is just going to used as console app in my ubuntu server, but im not sure how i should deploy this, which files i should put up on the server and how do i execute it in server, and stuff like that.
Any pointers would be useful for me.
or try to use sbt, IDEA has a plugin with sbt, the wiki of it has an explanation on how to use it.
I usually use sbt directly in Terminal instead of running in IDE.
1) First you need to find "Select Run/Debug Configuration" button at the top of your screen
Click on it and choose edit
Create new one, if you haven't got it yet.
Your program parameters should be written in "Program parameters" field
2) Compile your .scala files with scalac and you'll got .class files.
Then deploy it, as you usually do with java code. Hence you don't need to install scala on target machine - all you need is JDK.