[英]How to add command-line arguments while running a program using Makefile?
I have the following Main class in java where I pass arguments from the command-line:我在 java 中有以下 Main 类,我在其中从命令行传递参数:
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:我有一个 Makefile 和选项 make
run-java
我运行程序:
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.我想要做的是传递命令行参数 (argv),它们是要转换的文件的名称,从 makefile 到 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?如何更改我的 Makefile 以便
run-java:
可以允许我传递参数并将其发送到主程序?
Thanks !谢谢 !
Use a variable:使用变量:
make run-java ARGS="arg1 arg2"
And then in the makefile:然后在makefile中:
run-java
java Main $(ARGS)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.