I am trying to get a string to be passed into ant in order for it to be ran as a parameter inside of a java function. Does anyone know how to do this?
Defining a string, this string has to have white spaces in between. For example, "Hello world hi"
<target name = "run" depends="compile">
<property name="input" value="report" />
<java classname="assn4">
<classpath>
<pathelement path="."/>
</classpath>
<arg line="${input}"/>
</java>
</target>
Here is the complete working example.
Test.java
public class Test
{
public static void main(String[] args)
{
String userString = args[0];
System.out.println("*****"+ userString+"*****");
}
}
build.xml
<?xml version="1.0"?>
<project name="sample" basedir="." default="testJavaArgument">
<target name="testJavaArgument">
<java fork="true" failonerror="yes" classname="Test">
<classpath>
<pathelement path="."/>
</classpath>
<arg value="Hello World!"/>
</java>
</target>
</project>
Output
testJavaArgument:
[java] *****Hello World!*****
BUILD SUCCESSFUL
Total time: 1 second
The simple problem you have is: change from <arg line="some value">
to <arg value="some value">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.