How to pass parameters from command line to a java program through makefile

Ranger 22

My first question in stack overflow... Kind of excited but still struggling in the problem.

Alright, My question is how to pass parameters from command line to a java program through makefile.

Honestly I don't really know wether my description is correct....... Cause I don't really know much about makefile... In my assignment, the description is that we must develop a Makefile for GNU make to build our program. For example, the command lines

make

mipsim -v < test1.cmd > test1.log

will build the ISS (a simulator we made) and then run it with debugging output, taking input commands from the file test1.cmd and writing result to test1.log.

I have finished the program but I don't know how to make the things above happen. What I know so far is just to use makefile to make the .class file from .java file.... I have no idea about how to get test1.cmd as my input file's name and test1.log as my output file's name from command lines.... I guess these two names probably will get into my program through String[] args in the main function...

Could anybody give me some help please?

Thanks

laune

There is some confusion as to the issues.

First, compile Java using make is a little... iffy. (Most people use ant or maven.) However, if you don't mind a little overhead, you can do it using make. You probably should run make from a directory at the root of the Java package hierarchy. You can determine all Java files below using make macros. Hint: shell:

JAVA_FILES = $(shell find -name \*.java)

Then you run javac. (Make sure to define all path names to compilers etc. using make macros.) With Java, it's not easy to derive a make target, because .class files are not 1:1 w.r.t. java files. I just use a target "compile", depending on all the java files, and touch a file acting as a dummy target.

Second, the execution. To invoke a Java program that is not in an executable jar, you set the classpath (option -cp), specify the main class name and add command line parameters. I'd have to know what "mipsim" is - probably a shell script for doing just that. Anyway, a make target could be the log file:

%.log : %.cmd
        ${JAVA_HOME}/bin/java -cp ${ROOT} <$< >$@ 

Now, make test1.cmd should run your program.

Note: Redirection is not specified by program arguments; this is handled by the shell.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to run brew command through java program?

Passing values to java program from a command line, how does it work?

Running Java Program from Command Line Linux

Pass arguments into C program from command line

How do I run a Java program from the command line on Windows?

classpath - running a java program from the command line

How to stop the execution of Java program from Command line?

How to pass parameters into JMX MBean function from command line

how to pass double value as a command line argument in java program

how to pass command-line arguments to a program run with the open command?

How to pass parameters through Java Validator messages?

How to pass parameters to ruby command line script

How to pass an array to python through command line

How to pass/retrieve DOS command-line parameters in a 16-bit assembly program?

How to pass parameters to SoapUI in command line?

How to pass argument from Makefile to a program?

How can I pass all command line arguments through Clap to another program?

How to get input from user and pass it to an interactive command line program triggered by subprocess call in python?

How to run ant command through java program?

How do I pass a command-line program a list of files from a directory?

Pass command line parameters to a program inside the shell script

How can I pass all command line arguments to a program in a Makefile?

How to launch an interactive command line interface program from Java?

How to pass a variable to a command line program?

How to pass parameters to node.js from Windows command line

How to pass parameters from a bat file or a command line to a plpgsql function?

How pass grouped parameters in command line

How to pass parameters to a command in bash when run line by line?

How do I build a wixproj from command line with the same parameters as through Visual Studio?

TOP Ranking

HotTag

Archive