Reputation: 2356
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.
Upvotes: 15
Views: 28768
Reputation: 1
Run->Edit Configurations and then change the class name to which you want run.
Example: Change com.package.Main
to com.package.Stopwatch
if you want to run Stopwatch Class(File).
Upvotes: 0
Reputation: 340
You can also use the not-so-new-now Scratch Files; they're pretty good for trying simple things out and they are saved, so you can easily find them under recent files, or by name.
Upvotes: 4
Reputation: 12724
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:
After that you will be able to choose an option e.g., Run, Debug or Run with Coverage:
In this case IDEA will just run your class without building the entire project.
Upvotes: 9
Reputation: 12592
Right click your class in the left side bar. Hit Run. But your class must have a main method.
Upvotes: 3
Reputation: 1294
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.
To change the run configurations, you can follow below steps.
Run
tab at the top Toobar and click on Edit Configurations
.+
icon and select Application
. This opens a new popup window where you can add all your VM arguments & Program arguments similar to Eclipse.Upvotes: 4