
Originally Posted by
Andrew Swan
There's no Java API for invoking Roo, so your only option is to use
java.lang.Runtime#exec() as you would for invoking any external program from Java. Note that because Roo runs from a batch file, you might need to invoke CMD.EXE with the /C argument instead of directly calling roo.bat (this is a batch file thing, not a Roo thing). So the call to exec would look like this:
Code:
String[] command = {"cmd", "/c", "roo.bat", "script", "application.roo"};
Process process = Runtime.getRuntime().exec(command);
I have written a mini program as follows to see how this works:
PHP Code:
package io;
import java.io.*;
public class ExecuteDosCommand {
public static void main(String[] args) {
try {
String[] command = {"cmd", "/c", "roo.bat", "script",
"C:\\roo_scripts\\application.roo"};
Process p = Runtime.getRuntime().exec(command);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the error output from the command
String s = null;
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
// output from the command
System.out.println("Here is the output from the command");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
System.out.println("I am In try");
} catch (Exception e) {
System.out.println("I am In catch");
}
}
}
However, on running this programme, I get the following error:
Code:
run:
Here is the standard error of the command (if any):
Exception in thread "Spring Roo JLine Shell" java.lang.UnsatisfiedLinkError: C:\Users\Sir Tumaini Kilimba\AppData\Local\Temp\jline_.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at jline.WindowsTerminal.loadLibrary(WindowsTerminal.java:322)
at jline.WindowsTerminal.initializeTerminal(WindowsTerminal.java:240)
at org.springframework.roo.shell.jline.JLineShell.createAnsiWindowsReader(JLineShell.java:173)
at org.springframework.roo.shell.jline.JLineShell.run(JLineShell.java:73)
at java.lang.Thread.run(Unknown Source)
Does anyone know what may cause this? Am on a Windows 7, 64 Bit OS...