I'm using vim to learn scala. I write some scala code in vim, and then:
:!scalac xxx.scala
:!scala Xxx
Is there any way to run the code easier?
Press "control o" to save the file and then press enter. Press "control x" to exit the nano editor. To compile the code, type "scalac hello_world. scala" and press enter.
The 'scalac' command is used to compile the Scala program and it will generate a few class files in the current directory. One of them will be called HelloWorld.
I suggest you try SBT - http://code.google.com/p/simple-build-tool/
You'll probably want a few shells open and you'll have to bounce between vim and your SBT session, but in general SBT streamlines Scala development to the point where it feels like an interpreted language. A few handy SBT tips:
Run sbt at the shell in your project directory to automatically create your project structure. To get started quickly, edit a file in that project named src/main/scala/MyFile.scala
In one sbt shell, run ~compile to continuously detect and compile changes as you make them.
In another sbt shell, run 'console'. This gives you a normal Scala REPL with your project and its dependencies already on the CLASSPATH.
From that scala shell you can run :load to load your Scala file and run it. Or you can simply import and instantiate classes and call functions defined in your Scala code to test functionality. When you make changes to the file, :replay in the REPL will load those changes and run all entered commands again.
This setup works great for rapid web development in conjunction with Scalatra. From sbt you can directly deploy and run your webapp with 'jetty-run' and then detect, recompile and deploy changes automatically with ~prepare-webapp. Then you just keep a browser open and see changes as you make them. A good getting started guide for this is here: http://blog.everythings-beta.com/?p=430 You can have a web app running in 5 minutes or so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With