0

I have the following Main class in java where I pass arguments from the command-line:

public class Main {
    public static void main (String [] args) {
        Conversion c = new Conversion();
        c.convertHPP(args[0], args[1]);
        c.convertCPP(args[0], args[1]);
    }
}

I have a Makefile and with the option make run-java I run the program:

JFLAGS = -g
JC = javac

.SUFFIXES: .java .class

.java.class:
    $(JC) $(JFLAGS) $*.java

CLASSES = \
          Main.java \
          Conversion.java \
          Book.java

make-java: classes

classes: $(CLASSES:.java=.class)

run-java:
    java Main
    
clean:
    $(RM) *.class 

What I want to do is to pass the command-line arguments (argv) which are the name of the files to convert, from the makefile to the main. I want to do something like this in the terminal:

make java-run arg1 arg2

How can I change my Makefile so that the run-java: can allow me to pass arguments and to send it to the main?

Thanks !

fabian
  • 80,457
  • 12
  • 86
  • 114
Will Wost
  • 105
  • 2
  • 9
  • This might help. [passing-additional-variables-from-command-line-to-make](https://stackoverflow.com/questions/2826029/passing-additional-variables-from-command-line-to-make) – abhijit gupta Nov 09 '20 at 17:25

1 Answers1

1

Use a variable:

make run-java ARGS="arg1 arg2"

And then in the makefile:

run-java
    java Main $(ARGS)
HardcoreHenry
  • 5,909
  • 2
  • 19
  • 44