aspose file tools*
The moose likes Beginning Java and the fly likes How to call program arguments of different class through java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to call program arguments of different class through java code" Watch "How to call program arguments of different class through java code" New topic
Author

How to call program arguments of different class through java code

Gokul Raam
Greenhorn

Joined: Dec 29, 2008
Posts: 3
Hi,

There are some couple of classes which has their own program arguments to execute it. Now i need to create Main execution class and to call all classes. while calling that classes they require to pass arguments. so if i have those program arguments in my code then i will develop main execution class. Kindly let me know if somebody needs more clarity...

Thanks in advance
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

It's not clear to me what you're asking, but it sounds like it might be something like this:



If your question is how to call C1's main and C2's main from Main's main, the answer is that they're just regular methods that you can call like any other:



HOWEVER, that would be a rather unusual requirement, and it suggests a design problem to me. (I can't give you anything more specific about what's wrong without knowing more about what you're trying to do and why you're trying to do it this way.)

If this is not what you're asking, please clarify, using a tiny example like I did to illustrate the issue.
Gokul Raam
Greenhorn

Joined: Dec 29, 2008
Posts: 3
Hi Jeff,

Thanks for your reply.

You have guessed almost correct.

i will explain more with your example.

there are C1 and C2 clasees and I have Main class and from Main class i need to call C1 and C2 in order to run continuously.
The problem is that both C1 and C2 have different program arguments which are mentioned in run configurations of eclipse and in Main class if i use the below method to call those C1 and C2 classes I will error.

C1.main(args);
C2.main(args);

So Now i need to get those program arguments in code and i need to call those C1 and C2 classes like

args1 = "Program arguments of C1 class"
args2 = "Program arguments of C2 class"

C1.main(args1);
C2.main(args2);


Kindly let me know if you need more clarification.
thanks in advance.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Gokul Raam wrote:
there are C1 and C2 clasees and I have Main class and from Main class i need to call C1 and C2 in order to run continuously.
The problem is that both C1 and C2 have different program arguments which are mentioned in run configurations of eclipse and in Main class if i use the below method to call those C1 and C2 classes I will error.

C1.main(args);
C2.main(args);

So Now i need to get those program arguments in code and i need to call those C1 and C2 classes like

args1 = "Program arguments of C1 class"
args2 = "Program arguments of C2 class"

C1.main(args1);
C2.main(args2);



So, what's stopping you? Clearly you know how to call C1 with one set of args, and C2 with another set of args. If you're asking where to get those args from, there's no way anybody here can know that. Only you know what those args are supposed to be and where they're coming from.

If you're asking how to get them from "configurations of eclipse", then that can be found in the eclipse docs, or eclipse tutorial, or eclipse forum. But basically, there will be somewhere in eclipse where you can tell it what args to pass when you start your main program, so you just need to fill that in with something like


and then your Main has to parse those out to figure out which args go with each C1 and C2. Maybe there are a known, fixed number for each, so that, for example, args[0]-args[2] go to C1 and args[3]-args[5] go to C2. Or maybe you provide a special delimiter, such as "--" or ":::" or something, and when Main sees that, it knows everything before it is for C1 and everything after is for C2.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call program arguments of different class through java code
 
Similar Threads
Main method inheritance
Determine from which main class the call came from to a method
main(String[]args)
What is the difference between 'deep' and 'shallow' binding?
classloader