Run multiple java main classes at once in netbeans










1















I have several main classes with different arguments. I also added the arguments to each class successfully.



But the problem is: I have to start each class manually every time (e.g. click on Run-File).



Is there a solution where I can start all the classes with one click in netbeans? And the classes should also follow a specific order.










share|improve this question




























    1















    I have several main classes with different arguments. I also added the arguments to each class successfully.



    But the problem is: I have to start each class manually every time (e.g. click on Run-File).



    Is there a solution where I can start all the classes with one click in netbeans? And the classes should also follow a specific order.










    share|improve this question


























      1












      1








      1








      I have several main classes with different arguments. I also added the arguments to each class successfully.



      But the problem is: I have to start each class manually every time (e.g. click on Run-File).



      Is there a solution where I can start all the classes with one click in netbeans? And the classes should also follow a specific order.










      share|improve this question
















      I have several main classes with different arguments. I also added the arguments to each class successfully.



      But the problem is: I have to start each class manually every time (e.g. click on Run-File).



      Is there a solution where I can start all the classes with one click in netbeans? And the classes should also follow a specific order.







      java class netbeans main run-configuration






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 5 '12 at 0:40







      David Sonnenfeld

















      asked Dec 5 '12 at 0:10









      David SonnenfeldDavid Sonnenfeld

      44741329




      44741329






















          5 Answers
          5






          active

          oldest

          votes


















          1














          1. Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.


          2. You can create any number of new classes under one project by going to File -> New File -> and completing the walk-thru. At this point of time you should not include main method in these classes. Do not open a new project each time.


          3. Create yet another file (by going thru File -> New File etc.). This time in this new class include code for the main method. From the main method you can call any number of classes by creating instances of those classes. The classes will be executed in the order you called them under the main method as long as all those classes are included in the same folder, that is under the same project.


          It looks like you are writing java programs just as do it in the procedural languages. To some extent java classes are like subroutines of the procedural languages. Calling them is done by creating an instance of that class.






          share|improve this answer






























            0














            Maybe call to each class seperately? For instance:



            FirstClass.java



            SecondClass.java



            ThirdClass.java



            In FirstClass, you could call on SecondClass to pop-up, simply with a setVisible(true) if that's all you want it to do. Then in the SecondClass call to ThirdClass to pop-up the same way.



            I'm not sure if this is what you wanted as there's no code to go off of, but just something to get you thinking.






            share|improve this answer























            • no cant do that.. I have 3 different server classes and 2 client classes... so 5 classes with main methods, in a server-client system

              – David Sonnenfeld
              Dec 5 '12 at 1:41


















            0














            You can attempt to run multiple main classes via different run configurations.



            See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments






            share|improve this answer






























              0














              Set one class as main class through properties and run and in that you can Use following code:



              ClassName variableName = new ClassName();
              variableName.setVisible(true);


              ex- Suppose my class name is Dog and I use frame as variable name



              Dog frame = new Dog();
              frame.setVisible(true);*emphasized text*





              share|improve this answer
































                0














                Drawing from comments and the question, I understand that you want to run ~5 different java programs simultaneously in your IDE (netbeans,) and the startup sequence has to be in a particular order. I assume you don't need CLI input for these programs once they're running.



                I'm unaware of a netbeans way to accomplish your goal, although in Eclipse a Launch Group would satisfy your requirements.



                IDE's aside, we can programmatically accomplish this goal anyway. The main() method in Java is just a static method, so if all your main methods are in one project, then you can just make a LaunchSequence class or something and do the following:



                public static void main(String args)

                Thread t1 = new Thread()

                @Override
                public void run()

                ServerOneClass.main(whateverArgsItNeeds);

                ;
                t1.start();
                Thread t2 = new Thread()

                @Override
                public void run()

                ClientOneClass.main(whateverArgsItNeeds);

                ;
                t2.start();
                //and so on.
                //The order is enforced by the order you call start(), not the order in which you declare the threads



                If you have the code for these things in different projects, then you could make a new project and add them as dependencies.



                If you do actually need user input for all the programs, you may benefit from looking at Running a java program from another java program






                share|improve this answer






















                  Your Answer






                  StackExchange.ifUsing("editor", function ()
                  StackExchange.using("externalEditor", function ()
                  StackExchange.using("snippets", function ()
                  StackExchange.snippets.init();
                  );
                  );
                  , "code-snippets");

                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "1"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader:
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  ,
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );













                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13714233%2frun-multiple-java-main-classes-at-once-in-netbeans%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  1














                  1. Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.


                  2. You can create any number of new classes under one project by going to File -> New File -> and completing the walk-thru. At this point of time you should not include main method in these classes. Do not open a new project each time.


                  3. Create yet another file (by going thru File -> New File etc.). This time in this new class include code for the main method. From the main method you can call any number of classes by creating instances of those classes. The classes will be executed in the order you called them under the main method as long as all those classes are included in the same folder, that is under the same project.


                  It looks like you are writing java programs just as do it in the procedural languages. To some extent java classes are like subroutines of the procedural languages. Calling them is done by creating an instance of that class.






                  share|improve this answer



























                    1














                    1. Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.


                    2. You can create any number of new classes under one project by going to File -> New File -> and completing the walk-thru. At this point of time you should not include main method in these classes. Do not open a new project each time.


                    3. Create yet another file (by going thru File -> New File etc.). This time in this new class include code for the main method. From the main method you can call any number of classes by creating instances of those classes. The classes will be executed in the order you called them under the main method as long as all those classes are included in the same folder, that is under the same project.


                    It looks like you are writing java programs just as do it in the procedural languages. To some extent java classes are like subroutines of the procedural languages. Calling them is done by creating an instance of that class.






                    share|improve this answer

























                      1












                      1








                      1







                      1. Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.


                      2. You can create any number of new classes under one project by going to File -> New File -> and completing the walk-thru. At this point of time you should not include main method in these classes. Do not open a new project each time.


                      3. Create yet another file (by going thru File -> New File etc.). This time in this new class include code for the main method. From the main method you can call any number of classes by creating instances of those classes. The classes will be executed in the order you called them under the main method as long as all those classes are included in the same folder, that is under the same project.


                      It looks like you are writing java programs just as do it in the procedural languages. To some extent java classes are like subroutines of the procedural languages. Calling them is done by creating an instance of that class.






                      share|improve this answer













                      1. Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.


                      2. You can create any number of new classes under one project by going to File -> New File -> and completing the walk-thru. At this point of time you should not include main method in these classes. Do not open a new project each time.


                      3. Create yet another file (by going thru File -> New File etc.). This time in this new class include code for the main method. From the main method you can call any number of classes by creating instances of those classes. The classes will be executed in the order you called them under the main method as long as all those classes are included in the same folder, that is under the same project.


                      It looks like you are writing java programs just as do it in the procedural languages. To some extent java classes are like subroutines of the procedural languages. Calling them is done by creating an instance of that class.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 3 '14 at 20:01









                      user3559041user3559041

                      211




                      211























                          0














                          Maybe call to each class seperately? For instance:



                          FirstClass.java



                          SecondClass.java



                          ThirdClass.java



                          In FirstClass, you could call on SecondClass to pop-up, simply with a setVisible(true) if that's all you want it to do. Then in the SecondClass call to ThirdClass to pop-up the same way.



                          I'm not sure if this is what you wanted as there's no code to go off of, but just something to get you thinking.






                          share|improve this answer























                          • no cant do that.. I have 3 different server classes and 2 client classes... so 5 classes with main methods, in a server-client system

                            – David Sonnenfeld
                            Dec 5 '12 at 1:41















                          0














                          Maybe call to each class seperately? For instance:



                          FirstClass.java



                          SecondClass.java



                          ThirdClass.java



                          In FirstClass, you could call on SecondClass to pop-up, simply with a setVisible(true) if that's all you want it to do. Then in the SecondClass call to ThirdClass to pop-up the same way.



                          I'm not sure if this is what you wanted as there's no code to go off of, but just something to get you thinking.






                          share|improve this answer























                          • no cant do that.. I have 3 different server classes and 2 client classes... so 5 classes with main methods, in a server-client system

                            – David Sonnenfeld
                            Dec 5 '12 at 1:41













                          0












                          0








                          0







                          Maybe call to each class seperately? For instance:



                          FirstClass.java



                          SecondClass.java



                          ThirdClass.java



                          In FirstClass, you could call on SecondClass to pop-up, simply with a setVisible(true) if that's all you want it to do. Then in the SecondClass call to ThirdClass to pop-up the same way.



                          I'm not sure if this is what you wanted as there's no code to go off of, but just something to get you thinking.






                          share|improve this answer













                          Maybe call to each class seperately? For instance:



                          FirstClass.java



                          SecondClass.java



                          ThirdClass.java



                          In FirstClass, you could call on SecondClass to pop-up, simply with a setVisible(true) if that's all you want it to do. Then in the SecondClass call to ThirdClass to pop-up the same way.



                          I'm not sure if this is what you wanted as there's no code to go off of, but just something to get you thinking.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 5 '12 at 0:46









                          CodeAddictCodeAddict

                          1312517




                          1312517












                          • no cant do that.. I have 3 different server classes and 2 client classes... so 5 classes with main methods, in a server-client system

                            – David Sonnenfeld
                            Dec 5 '12 at 1:41

















                          • no cant do that.. I have 3 different server classes and 2 client classes... so 5 classes with main methods, in a server-client system

                            – David Sonnenfeld
                            Dec 5 '12 at 1:41
















                          no cant do that.. I have 3 different server classes and 2 client classes... so 5 classes with main methods, in a server-client system

                          – David Sonnenfeld
                          Dec 5 '12 at 1:41





                          no cant do that.. I have 3 different server classes and 2 client classes... so 5 classes with main methods, in a server-client system

                          – David Sonnenfeld
                          Dec 5 '12 at 1:41











                          0














                          You can attempt to run multiple main classes via different run configurations.



                          See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments






                          share|improve this answer



























                            0














                            You can attempt to run multiple main classes via different run configurations.



                            See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments






                            share|improve this answer

























                              0












                              0








                              0







                              You can attempt to run multiple main classes via different run configurations.



                              See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments






                              share|improve this answer













                              You can attempt to run multiple main classes via different run configurations.



                              See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Oct 18 '13 at 11:14









                              xelamitchellxelamitchell

                              3501517




                              3501517





















                                  0














                                  Set one class as main class through properties and run and in that you can Use following code:



                                  ClassName variableName = new ClassName();
                                  variableName.setVisible(true);


                                  ex- Suppose my class name is Dog and I use frame as variable name



                                  Dog frame = new Dog();
                                  frame.setVisible(true);*emphasized text*





                                  share|improve this answer





























                                    0














                                    Set one class as main class through properties and run and in that you can Use following code:



                                    ClassName variableName = new ClassName();
                                    variableName.setVisible(true);


                                    ex- Suppose my class name is Dog and I use frame as variable name



                                    Dog frame = new Dog();
                                    frame.setVisible(true);*emphasized text*





                                    share|improve this answer



























                                      0












                                      0








                                      0







                                      Set one class as main class through properties and run and in that you can Use following code:



                                      ClassName variableName = new ClassName();
                                      variableName.setVisible(true);


                                      ex- Suppose my class name is Dog and I use frame as variable name



                                      Dog frame = new Dog();
                                      frame.setVisible(true);*emphasized text*





                                      share|improve this answer















                                      Set one class as main class through properties and run and in that you can Use following code:



                                      ClassName variableName = new ClassName();
                                      variableName.setVisible(true);


                                      ex- Suppose my class name is Dog and I use frame as variable name



                                      Dog frame = new Dog();
                                      frame.setVisible(true);*emphasized text*






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Dec 13 '14 at 0:21









                                      AbcAeffchen

                                      8,467123552




                                      8,467123552










                                      answered Dec 13 '14 at 0:04









                                      Robbin SinghRobbin Singh

                                      2515




                                      2515





















                                          0














                                          Drawing from comments and the question, I understand that you want to run ~5 different java programs simultaneously in your IDE (netbeans,) and the startup sequence has to be in a particular order. I assume you don't need CLI input for these programs once they're running.



                                          I'm unaware of a netbeans way to accomplish your goal, although in Eclipse a Launch Group would satisfy your requirements.



                                          IDE's aside, we can programmatically accomplish this goal anyway. The main() method in Java is just a static method, so if all your main methods are in one project, then you can just make a LaunchSequence class or something and do the following:



                                          public static void main(String args)

                                          Thread t1 = new Thread()

                                          @Override
                                          public void run()

                                          ServerOneClass.main(whateverArgsItNeeds);

                                          ;
                                          t1.start();
                                          Thread t2 = new Thread()

                                          @Override
                                          public void run()

                                          ClientOneClass.main(whateverArgsItNeeds);

                                          ;
                                          t2.start();
                                          //and so on.
                                          //The order is enforced by the order you call start(), not the order in which you declare the threads



                                          If you have the code for these things in different projects, then you could make a new project and add them as dependencies.



                                          If you do actually need user input for all the programs, you may benefit from looking at Running a java program from another java program






                                          share|improve this answer



























                                            0














                                            Drawing from comments and the question, I understand that you want to run ~5 different java programs simultaneously in your IDE (netbeans,) and the startup sequence has to be in a particular order. I assume you don't need CLI input for these programs once they're running.



                                            I'm unaware of a netbeans way to accomplish your goal, although in Eclipse a Launch Group would satisfy your requirements.



                                            IDE's aside, we can programmatically accomplish this goal anyway. The main() method in Java is just a static method, so if all your main methods are in one project, then you can just make a LaunchSequence class or something and do the following:



                                            public static void main(String args)

                                            Thread t1 = new Thread()

                                            @Override
                                            public void run()

                                            ServerOneClass.main(whateverArgsItNeeds);

                                            ;
                                            t1.start();
                                            Thread t2 = new Thread()

                                            @Override
                                            public void run()

                                            ClientOneClass.main(whateverArgsItNeeds);

                                            ;
                                            t2.start();
                                            //and so on.
                                            //The order is enforced by the order you call start(), not the order in which you declare the threads



                                            If you have the code for these things in different projects, then you could make a new project and add them as dependencies.



                                            If you do actually need user input for all the programs, you may benefit from looking at Running a java program from another java program






                                            share|improve this answer

























                                              0












                                              0








                                              0







                                              Drawing from comments and the question, I understand that you want to run ~5 different java programs simultaneously in your IDE (netbeans,) and the startup sequence has to be in a particular order. I assume you don't need CLI input for these programs once they're running.



                                              I'm unaware of a netbeans way to accomplish your goal, although in Eclipse a Launch Group would satisfy your requirements.



                                              IDE's aside, we can programmatically accomplish this goal anyway. The main() method in Java is just a static method, so if all your main methods are in one project, then you can just make a LaunchSequence class or something and do the following:



                                              public static void main(String args)

                                              Thread t1 = new Thread()

                                              @Override
                                              public void run()

                                              ServerOneClass.main(whateverArgsItNeeds);

                                              ;
                                              t1.start();
                                              Thread t2 = new Thread()

                                              @Override
                                              public void run()

                                              ClientOneClass.main(whateverArgsItNeeds);

                                              ;
                                              t2.start();
                                              //and so on.
                                              //The order is enforced by the order you call start(), not the order in which you declare the threads



                                              If you have the code for these things in different projects, then you could make a new project and add them as dependencies.



                                              If you do actually need user input for all the programs, you may benefit from looking at Running a java program from another java program






                                              share|improve this answer













                                              Drawing from comments and the question, I understand that you want to run ~5 different java programs simultaneously in your IDE (netbeans,) and the startup sequence has to be in a particular order. I assume you don't need CLI input for these programs once they're running.



                                              I'm unaware of a netbeans way to accomplish your goal, although in Eclipse a Launch Group would satisfy your requirements.



                                              IDE's aside, we can programmatically accomplish this goal anyway. The main() method in Java is just a static method, so if all your main methods are in one project, then you can just make a LaunchSequence class or something and do the following:



                                              public static void main(String args)

                                              Thread t1 = new Thread()

                                              @Override
                                              public void run()

                                              ServerOneClass.main(whateverArgsItNeeds);

                                              ;
                                              t1.start();
                                              Thread t2 = new Thread()

                                              @Override
                                              public void run()

                                              ClientOneClass.main(whateverArgsItNeeds);

                                              ;
                                              t2.start();
                                              //and so on.
                                              //The order is enforced by the order you call start(), not the order in which you declare the threads



                                              If you have the code for these things in different projects, then you could make a new project and add them as dependencies.



                                              If you do actually need user input for all the programs, you may benefit from looking at Running a java program from another java program







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Nov 13 '18 at 22:34









                                              JeutnargJeutnarg

                                              8941120




                                              8941120



























                                                  draft saved

                                                  draft discarded
















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid


                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.

                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13714233%2frun-multiple-java-main-classes-at-once-in-netbeans%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  這個網誌中的熱門文章

                                                  How to read a connectionString WITH PROVIDER in .NET Core?

                                                  In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                                                  Museum of Modern and Contemporary Art of Trento and Rovereto