My program getting command line arguments. How can I pass it when I use Ant?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Can you be a bit more specific about what you're trying to do and how you're trying to do it?
If you're attempting to invoke the program using the
<exec>
task you might do the following:The only effective mechanism for passing parameters into a build is to use Java properties:
The following example demonstrates how you can check and ensure the expected parameters have been passed into the script
Extending Richard Cook's answer.
Here's the
ant
task to run any program (including, but not limited to Java programs):Here's the task to run a Java program from a
.jar
file:You can invoke either from the command line like this:
Make sure to use the
-Darg
syntax; if you ran this:then
ant
would try to run targetsarg0
andarg1
.What I did in the end is make a batch file to extract the CLASSPATH from the ant file, then run java directly using this:
In my build.xml:
In another script called 'run.sh':
It's no longer cross-platform, but at least it's relatively easy to use, and one could provide a .bat file that does the same as the run.sh. It's a very short batch script. It's not like migrating the entire build to platform-specific batch files.
I think it's a shame there's not some option in ant whereby you could do something like:
mpirun uses this type of syntax; ssh also can use this syntax I think.
If you do not want to handle separate properties for each possible argument, I suggest you'd use:
You can check if the property is not set using a specific target with an
unless
attribute and inside do:Putting it all together gives:
You can use it as follows:
The first two commands will prompt for the command-line arguments, whereas the latter won't.