Closed paulvi closed 10 years ago
Asnswered by @First Zero with reference to http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F
final Process process = new ProcessBuilder() .command(mvnPath, "clean", "test")
.directory(projectDirectory) .redirectErrorStream(true) .start();
//then grabbed the input stream
InputStreamReader isr = new InputStreamReader(process.getInputStream());
final BufferedReader reader = new BufferedReader(isr);
Here how node.js is launched
package org.nodeclipse.debug.launch;
public class LaunchConfigurationDelegate implements ILaunchConfigurationDelegate {
@Override
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
// skipped argument processing
String[] cmds = {};
cmds = cmdLine.toArray(cmds);
// Launch a process to run/debug. See also #71 (output is less or no output)
Process p = DebugPlugin.exec(cmds, workingPath, envp);
// no way to get private p.handle from java.lang.ProcessImpl
RuntimeProcess process = (RuntimeProcess)DebugPlugin.newProcess(launch, p, Constants.PROCESS_MESSAGE);
But this way fails for mvn
or gradle
asked on http://stackoverflow.com/questions/21177198/run-maven-gradle-or-other-batch-based-script-from-java-and-then-eclipse
I am making Eclipse plugin https://github.com/Nodeclipse/nodeclipse-1/tree/master/org.nodeclipse.enide.maven that run alternative build from within Eclipse (e.g. for project that have both
pom.xml
andbuild.gradle
do run withmvn package
orgradle build
)But entry point for both of them are batch
.bat
files on Windows and bash on Linux. For Windows running from Java would look likebut that will start new window, while I want it to see running in Eclipse Console.
There must be something like http://commons.apache.org/proper/commons-exec/ but in Eclipse way I guess. How to run such script from Eclipse and see output in Console? This is meant to be alternative and not dependent on m2e and Gradle Integration.