Javeria Habib
Javeria Habib

Reputation: 557

Send output to program arguments in Java eclipse automatically

In my ANJI (http://anji.sourceforge.net/) java project, I have two java file in package com.anji.neat.

One file names evolver.java which needs one program argument. The output champ-id from evolver.java is to be added as args[1] along with the previous argument fed to evolver.java

How can I add this output to Program Arguments without manually adding it? Plus is it possible that I execute these two java files in one run?

I know the question is complex, but someone kindlu help. I am new to java, so do not get things.

Upvotes: 0

Views: 162

Answers (2)

Joop Eggen
Joop Eggen

Reputation: 109547

It would become something "ugly" like:

public static void main(String[] args) {
    if (args.length == 1) {
       String extraArg;
       ...;
       args = new Strinng[] { args[0], nextArg };
       // main(args); return;
    }
    ...
}

Upvotes: 0

Juned Ahsan
Juned Ahsan

Reputation: 68715

I would suggest that you have main method only in one file, lets say in evolver.java. Add a normal method in your second file which takes two arguments, first argument is the command line argument received in evlover.java and second argument is the champ-id. Run your program by calling the main method of evolver.java. Process the command line argument and generate the champ-id. And after that call the method of your second class by passing both the arguments.

Upvotes: 2

Related Questions