2

enter image description hereI have an experimental project that used to write some ADT like stuff in which there are packages like linkedList, streams, sorting, stacks, sockets etc. Every class has own main method, Like in eclipse we can run the class from the option menu but how this can be done in intelliJ ?

Rajat
  • 2,467
  • 2
  • 29
  • 38
  • Simplest way is to open a class with `main` in the editor, then click on IntelliJ's `Run` menu and select `Run...` which will show a popup menu with the existing run configurations, meaning the existing `main` entry points - including the one of this class, even though you didn't explicitly create a run configuration for it yet. Select it, done. Henceforth, you'll have a run configuration for this one, too. – Dreamspace President May 05 '18 at 18:36
  • 1
    @DreamspacePresident, agreed, except that it's also in the right-click context menu of the editor, and I find that easier than moving my eyes off the code to the top menu. – alife Nov 07 '22 at 16:25
  • (Well ... I actually use a keyboard shortcut.) – Dreamspace President Nov 21 '22 at 15:58

2 Answers2

0

You can create your run configuration for each main class from Run -> Edit configuration.

Here's the guide link

Editing answer because of comments below:

See this link: imgur.com/a/1H5Xhj8 Here I ran class A and B and I can see in run config menu. Now I created class JJ. I still can see green triangles on this class but not in dropdown. N.B: I'm not using ultimate version but community edition. Hope it's not an issue

Shubhendu Pramanik
  • 2,711
  • 2
  • 13
  • 23
  • IntelliJ automatically have run config for files having public static void main. he is not getting this option as he has not configured source folder. – Number945 May 05 '18 at 14:29
  • @BreakingBenjamin For this you need to go to each class individually and run it every time. If you create run config you can do it from menu. So create the config once and you don't need to search the file each time. Isn't it less time consuming. – Shubhendu Pramanik May 05 '18 at 15:38
  • No u need not do it. `src` is the parent folder for all. Is there any other reason why u down voted ? It is foolish to edit configurations when IntelliJ provides you with one. Also, the main reason of downvoting your answer is that it is a comment and not an answer actually : https://meta.stackexchange.com/questions/17447/answer-or-comment-whats-the-etiquette – Number945 May 05 '18 at 15:45
  • @BreakingBenjamin the reason for downvote is you don't have to follow the steps to bring those `green triangles`. If you have `main` class those will appear automatically. Secondly even after doing so it the classes will not appear in existing run config dropdown. I just tested on my local. It's not personal. And about comment like answer, if your answer is self explanatory you don't need to add unnecessary lines where it's already there in the URL I've provided – Shubhendu Pramanik May 05 '18 at 16:01
  • Really ? Are you sure ? Did you checked the 'J' icon in above figure ? Did you got that in ur local too ? Most of the times sources are preconfigured when u create a new project in IntelliJ provided you create it wisely. This `J` won't appear then. See the image above. Now see this : https://stackoverflow.com/questions/4904052/what-does-this-symbol-mean-in-intellij-red-circle-on-bottom-left-corner-of-fil Decide for urself then if what i am saying is right or wrong. – Number945 May 05 '18 at 16:03
  • @BreakingBenjamin See this link: imgur.com/a/1H5Xhj8 Here I followed your steps -> ran class A and B and I can see in run config menu. Now I created class JJ. I still can see green triangles on this class but not in dropdown. N.B: I'm not using ultimate version but community edition. Hope it's not the issue – Shubhendu Pramanik May 05 '18 at 16:12
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170429/discussion-between-shubhendu-pramanik-and-breaking-benjamin). – Shubhendu Pramanik May 05 '18 at 16:13
0

See, you can also run your public static void main directly like in eclipse. IntelliJ automatically have this run config. But to have this all you need to do is set your source folder.

So, File> Project Structure > Modules , the select src and mark as sources.

enter image description here

For more details : https://www.jetbrains.com/help/idea/creating-and-managing-modules.html

After you have done this, you will see small green triangles on left near your public static void main from where you can run and debug.

enter image description here

You see that J small icon on top of Java icons files in project window on left. This is indication that you have not configured your sources folder .

See : What does this symbol mean in IntelliJ? (red circle on bottom-left corner of file name, with 'J' in it)

Number945
  • 4,631
  • 8
  • 45
  • 83
  • For this you need to go to each class individually and run it every time. If you create run config you can do it from menu. – Shubhendu Pramanik May 05 '18 at 15:38
  • @ShubhenduPramanik No u need not do it. `src` is the parent folder for all. Is there any other reason why u down voted ?Any standard java hierarchical package structure have scope for sources folder. It is industry standard.That's why IntelliJ assumes it. – Number945 May 05 '18 at 15:40
  • the reason for downvote is you don't have to follow the steps to bring those `green triangles`. If you have `main` class those will appear automatically. Secondly even after doing so it the classes will not appear in existing run config dropdown. I just tested on my local. It's not personal. And about comment like answer, if your answer is self explanatory you don't need to add unnecessary lines where it's already there in the URL I've provided – Shubhendu Pramanik May 05 '18 at 16:01
  • If you edit your answer and make it correct I'll undo the downvote ;) – Shubhendu Pramanik May 05 '18 at 16:03
  • See this link: https://imgur.com/a/1H5Xhj8 Here I followed your steps -> ran class `A` and `B` and I can see in run config menu. Now I created class `JJ`. I still can see green triangles on this class but not in dropdown. N.B: I'm not using ultimate version but community edition. Hope it's not the issue – Shubhendu Pramanik May 05 '18 at 16:12