Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ run single Java file

I am switching from Eclipse to IntelliJ, I'm trying to do something that's really simple to do in Eclipse. This is probably a simple question, but I have a project in IntelliJ with a bunch of small .java class files with main classes. These are just small practice programs I use for testing. I am trying to right click one of the java class files, then 'Run'. I'm expecting the class to run and see its output in the console - it looks like IntelliJ is instead trying to compile the entire project, including test classes.

How can I make IntelliJ just run the single class file without attempting to do a build of the entire project?

Also - In eclipse I am used to copying arguments to my main class into an input window when running a single java class. Is there a way to do this in IntelliJ.

Thanks, I know I can do this from a terminal, but for my purposes it would be helpful to quickly run small java programs from an ide.

like image 388
user619804 Avatar asked Dec 14 '16 05:12

user619804


3 Answers

Another option could be useful and quick for you. Just write your class with main method you want to run, and then press a little green triangle either behind your main method or behind your class name:

enter image description here

After that you will be able to choose an option e.g., Run, Debug or Run with Coverage:

enter image description here

In this case IDEA will just run your class without building the entire project.

like image 121
DimaSan Avatar answered Nov 04 '22 15:11

DimaSan


You can change the Default settings based on your needs, to either automatically build after each change or manually. This can be achieved by clicking on File -> Other Settings -> Default Settings. This is the popup window.

Default Preferences

To change the run configurations, you can follow below steps.

  1. Goto Run tab at the top Toobar and click on Edit Configurations.
  2. Click + icon and select Application. This opens a new popup window where you can add all your VM arguments & Program arguments similar to Eclipse.
like image 4
A.K.Desai Avatar answered Nov 04 '22 13:11

A.K.Desai


Right click your class in the left side bar. Hit Run. But your class must have a main method.

enter image description here

like image 3
Abdullah Khan Avatar answered Nov 04 '22 15:11

Abdullah Khan