Home > Blockchain >  Run multiple main methods in Java with Intellij
Run multiple main methods in Java with Intellij

Time:07-29

How do I run multiple main methods so that I can get both consoles loaded up inside of the run? My project only has 2 classes and both already has the static main function which you can tell by the green triangle in both of my class icons (the icons are top left of the image). Anyways I can toggle between both the client and the server clicking on one of the applications but for some reason I cant run both. Also keep in mind the reason client has a red "x" next to it is because I slightly changed the path to not dox my self but with the correct path I can only choose which one to run.

My screen

CodePudding user response:

I don't think you can run both main methods in same window of IntelliJ. If your application is like Client and Server, what I suggest is you can put client code in one application and server code in another and then open them in two different windows.

CodePudding user response:

Ok I figured it out. Anyways after you make both main methods you can edit configuration files then after setting the path and the main class for both of your applications click apply and ok. Then right click that box again (its labeled Client and is in the top right hand corner in my original picture) and click save configuration. If you dont have that setting then your probably good as long as on of your applications are not translucent. The last step is to then right click one of them and click run then right click the other one and click run. It works with a max of 5 (without changing your inteillJ settings)

  • Related