20

I just start using IntelliJ-14 and I want to know about a scratch file. If I create a java scratch can I compile this as a normal Java class. What I Have Already Tried Create a Java class in a scratch file but unable to find any way to compile this. What I am looking for rather than creating a new Java file in an existing project for running some test code I just want to use scratch file and write some test class with the main method and after complete running close the scratch file. Is that possible?

Pravin Divraniya
  • 4,223
  • 2
  • 32
  • 49

1 Answers1

24

Executability for Java scratch files was added in IntelliJ 15, so you must upgrade for that feature.

You have several option how to run/debug the scratch file:

  • Click the icon next to the main method/class
  • Hit Control+Shift+R (Control+Shift+F10 on Linux/Windows) somewhere within the scratch file
  • Right click inside the method/class and select appropriate run/debug option

enter image description here

Bohuslav Burghardt
  • 33,626
  • 7
  • 114
  • 109
  • I get an error http://stackoverflow.com/questions/35457087/error-running-scratch-file-in-intellij-15 – powder366 Feb 17 '16 at 16:27
  • Anyone knows how to build and run just the scratch file, without building the whole project? – Ivan Balashov Feb 08 '19 at 19:24
  • @IvanBalashov check here - https://stackoverflow.com/questions/10851880/intellij-idea-run-code-regardless-of-errors-in-unrelated-project-files – Yevgen Feb 19 '19 at 13:22