Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Maven, Gradle or other batch-based script from Java (and then Eclipse) #117

Closed
paulvi opened this issue Jan 16, 2014 · 2 comments
Closed

Comments

@paulvi
Copy link
Member

paulvi commented Jan 16, 2014

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 and build.gradle do run with mvn package or gradle 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 like

    Runtime.getRuntime().exec("cmd /c start mvn");

but 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.

@paulvi
Copy link
Member Author

paulvi commented Jan 17, 2014

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);

@paulvi
Copy link
Member Author

paulvi commented Jan 17, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant