"Run As Java" for Scala files in Eclipse

410 views
Skip to first unread message

Simon Ochsenreither

unread,
Jun 22, 2012, 1:19:47 PM6/22/12
to scala-...@googlegroups.com
Hi everyone,

I'm wondering if there is a reason why the "Run As" dialog offers not only "Scala" but also "Java". I never got the Java option to work and I have no idea what that option is supposed to do.
The presence of the "Java" option is extremely annoying because it transforms a simple "button click" to "button click" -> "dialog pops up" -> "choose option" -> "run it".

Any chance of get rid of that?

Thanks and bye!

Simon

Luc Bourlier

unread,
Jun 22, 2012, 4:14:41 PM6/22/12
to scala-...@googlegroups.com
The launch shortcut is provided from the JDT. It contains some code to check if the current editor or selection can be launch as a Java application. It is likely checking if it contains a main static method, in the Java model.
To support Java/Scala projects, we generate the info for the Scala files in the Java model. So the Scala application looks like valid Java application.

I'm not quite sure why it is not able to launch the application.

One tip that might make your life easier: in the preferences, Run/Debug > Launching, set 'Launch Operation' to 'Always launch the previously launched application'. Then when using the Run or Debug button, or the F11/Ctrl+F11 key shortcuts, Eclipse relaunches the last application, instead of trying to launch the current project. It is usually faster.

HTH,
Luc

Rüdiger Keller

unread,
Jun 22, 2012, 5:37:02 PM6/22/12
to scala-...@googlegroups.com

Hi,

This is indeed very annoying. The question remains why the Java version isn't working and why there's a Scala option at all if it's tricking JDT anyway.

Regards,
Rüdiger

Simon Ochsenreither

unread,
Jun 23, 2012, 10:28:17 AM6/23/12
to scala-...@googlegroups.com
Hi Luc,

thanks a lot for your reply!


The launch shortcut is provided from the JDT. It contains some code to check if the current editor or selection can be launch as a Java application. It is likely checking if it contains a main static method, in the Java model.
To support Java/Scala projects, we generate the info for the Scala files in the Java model. So the Scala application looks like valid Java application.

I'm not quite sure why it is not able to launch the application.

Error message: “Selection does not contain a main type.”
 
One tip that might make your life easier: in the preferences, Run/Debug > Launching, set 'Launch Operation' to 'Always launch the previously launched application'. Then when using the Run or Debug button, or the F11/Ctrl+F11 key shortcuts, Eclipse relaunches the last application, instead of trying to launch the current project. It is usually faster.

That's a great workaround! Thanks a lot!

Bye,

Simon

Ruediger Keller

unread,
Jun 25, 2012, 3:50:09 AM6/25/12
to scala-...@googlegroups.com
Hi,

sorry that my tone was so rude. I really appreciate all the hard work
that is going into the Scala IDE.

Is there a chance this is going to be fixed once the Scala IDE gets
its own editor, as planned according to the roadmap?

Regards,
Rüdiger


2012/6/22 Luc Bourlier <luc.bo...@typesafe.com>:

Arun Ramakrishnan

unread,
Jul 4, 2012, 2:35:57 AM7/4/12
to scala-...@googlegroups.com
On a more general note, I have always found it super annoying that Run Configurations are specific to each and every file ( not file type ) in eclipse. 

In my case what i have found handy is make generic keyboard shortcut to run files. With shortcuts you can specify the same key shortcut to run different source types based on the context. 

So, for me ⌘+k is the generic shortcut to run file that I currently have open as the active window in eclipse. 

Preferences > General > Keys
 Command: "Run Scala Application"   key: ⌘+k when:  "Editing Scala Source"
 Command: "Run Java Application"   key: ⌘+k  when:  "Editing Java Source"
 Command: "Run Groovy Application"   key: ⌘+k when:  "Editing Groovy Source"

hope that helps.

thanks
Arun
Reply all
Reply to author
Forward
0 new messages