Reputation: 5555
I want to create a batch file to run java project directly. I want this batch file to ask me to prompt inputs to be used in the run time for my project.
Upvotes: 2
Views: 12137
Reputation: 13103
I agree with the previous answer that it makes more sense to have your java program request input instead of attempting to do it in the batch program.
You don't say what operating system(s) you want to run this on, and that will make some difference to the batch file or script file.
Other things that will make a difference are the run-time environment on the system and whether the "default directory" is significant.
To invoke the java runtime, the system must recognize 'java' as a program name. On Windows and Unix (and therefore, I think, on Mac), this is done with a 'path' variable. The path is a "system variable", available to the command-line processor, that lists the directories in which the system will search for commands. For all system users to be able to use "java" on a command line, the path will need to be set globally, and your script cannot do that; you'll have to find out how to set it outside the script.
Alternately, your script could invoke java from its absolute location on the system, but of course different computers could have different values. Requiring that the path be set correctly on a given system for the script to run is probably the most common answer, but you should be aware of the problem.
Most systems have the concept of a "default directory" for a running program. If your java program opens the file "MyData.txt", then the java runtime will look for this file in the default directory; if it opens "..\MyData.txt", it will look in a sibling directory to the default on a Windows system (note backslash), etc. It can open files on an absolute path, though those tend to be system-specific. So hopefully your program is either expected to run on only one kind of system, or handles files in a general way, but if you're just starting out writing a script to run your program you should be aware of the issue. There's little that's more frustrating than a program that runs fine the way you have it set up for development but refuses to run in any other environment, especially if you aren't aware of these potential pitfalls.
You also don't say whether the program is primarily a UI program (one that has a point-and-click interface) or not; you should also be aware that there are ways to package such a program so that it can appear on a system as an icon that can be run by clicking on it with a mouse.
Upvotes: 5