Run multiple java main classes at once in netbeans
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
add a comment |
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
add a comment |
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
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
java class netbeans main run-configuration
edited Dec 5 '12 at 0:40
David Sonnenfeld
asked Dec 5 '12 at 0:10
David SonnenfeldDavid Sonnenfeld
44741329
44741329
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.
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.
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.
add a comment |
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.
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
add a comment |
You can attempt to run multiple main classes via different run configurations.
See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments
add a comment |
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*
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.
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.
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.
add a comment |
Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.
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.
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.
add a comment |
Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.
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.
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.
Open a new project with a specific name (File -> New project and complete the walk-thru) in NetBeans.
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.
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.
answered May 3 '14 at 20:01
user3559041user3559041
211
211
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
You can attempt to run multiple main classes via different run configurations.
See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments
add a comment |
You can attempt to run multiple main classes via different run configurations.
See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments
add a comment |
You can attempt to run multiple main classes via different run configurations.
See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments
You can attempt to run multiple main classes via different run configurations.
See http://wiki.netbeans.org/FaqTwoMainClassesWithArguments
answered Oct 18 '13 at 11:14
xelamitchellxelamitchell
3501517
3501517
add a comment |
add a comment |
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*
add a comment |
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*
add a comment |
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*
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*
edited Dec 13 '14 at 0:21
AbcAeffchen
8,467123552
8,467123552
answered Dec 13 '14 at 0:04
Robbin SinghRobbin Singh
2515
2515
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 13 '18 at 22:34
JeutnargJeutnarg
8941120
8941120
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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