I have one xml
file. I want to pass the xml
content into java command line argument.
abc.xml :
<a>
<block1>abc</block1>
<block2>xyz</block2>
<block3>pqr</block3>
</a>
Below is my groovy
/ java
code to get data from file and pass it into java command line argument.
File fl = new File("PATH/abc.xml")
String filecontent = fl.getText()
String cmd = "Java -cp abc.jar package.CLASSNAME "+filecontent
Process proc = Runtime.getRuntime().exec(cmd);
proc.waitFor()
This command is not executing just comes out of process. Why??
Untested code off the top of my head, so take it for what it's worth:
File fl = new File("PATH/abc.xml")
String filecontent = fl.readLines().*trim().join(' ')
String cmd = "java -cp abc.jar package.CLASSNAME \"${filecontent}\""
Process proc = Runtime.getRuntime().exec(cmd);
proc.waitFor()
Since this is Groovy code, I would also change it to invoke package.Classname.main() directly, rather than spinning off a process and another JVM:
File fl = new File("PATH/abc.xml")
String filecontent = fl.readLines().*trim().join(' ')
package.CLASSNAME.main([filecontent])
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.