Imagine a bacon-wrapped Ferrari. Still not better than our free technical reports.
See all our reports

Why we created YAPLJ (Yet Another Process Library for Java)


http://xkcd.com/974/

Why repeat activities manually when you could spend much more time and effort to create a process library instead?

This is a question we’ve been asking ourselves lately. As our company and engineering team grows, we’ve found that different projects have somewhat similar needs when it comes to libraries. Whenever this happens and we think that the library can be useful for the rest of the Java world, we open-source it.

So, without further ado let me introduce you to Yet Another Process Library for Java (similar to our YAZLJ). It is written in Java for Java and is meant to manage processes that you launch from your own programs.

Get the library from GitHub

Let me show you a quick example. In order to find out the version of the Java executable found in the path you would have the following line in your program.

new ProcessExecutor().command("java", "-version").execute();

You’re probably thinking, why would I need yet another process library? I’ve already got the JRE standard API library and the Apache Commons Exec? Well, yeah but when you use them and you use them heavily you discover writing lots of helpers to get rid of the boiler plate. Maybe even extending them to get more out of them. This is what happened over here. I’ll outline some of the features that the library provides on top of the other choices I mentioned.

  • Improved handling of streams
    • Reading/writing to streams
    • Redirecting stderr to stdout
  • Improved handling of timeouts
  • Improved checking of exit codes
  • Improved API
    • One liners for quite complex usecases
    • One liners to get process output into a String
    • Access to the Process object available
    • Support for async processes ( Future )
  • Improved logging with SLF4J API
  • Support for multiple processes

The project is hosted at GitHub, the CI is at Travis. The project page has tons of examples to get you started, the 1.4 release is available from Maven central so you should be all good to go. Take the library for a spin and let us know what you think in the comments section below, or ping me @toomasr :-)

  • iNikem

    Why do you use Travis for CIing you open source projects?

  • arhan

    What else would you suggest?

  • iNikem

    Don’t know, really :) CloudBees provides some free builds AFAIK. Just found http://teamcity.codebetter.com/ :)

  • http://www.zeroturnaround.com/ Toomas Römer

    Travis is super easy and has great integration with GitHub. Didn’t look much at alternatives.

    I have configured CloudBees offering for zt-zip a year or two ago but when I saw Travis I was like, why bother configuring a Jenkins job when I can just create a travis.yml file and click a checkbox :)

  • Felix

    You know what would be super awesome? Getting the PID of a subprocess. I know it’s not possible in Java (at least not in a plattform independent way) but it’s so aggrevating.