Search code examples
javaexectravis-ci

Can't run exec("cwebp ...") with Java in Travis CI


My Java Spring Application requires to run the cwebp-command (https://packages.debian.org/de/sid/libwebp-dev) and everything works fine on Windows and Mac. It doesn't work on Travis CI although "which cwebp" seems to work/not cause an error.

To be exactly my services tries to execute cwebp -q 82 e83376d1-3e5e-4d35-9e2e-9aaad2976984.jpg -o e83376d1-3e5e-4d35-9e2e-9aaad2976984.webp in /tmp/converter_service. The tmp-dir comes from System.getProperty("java.io.tmpdir"). The files and the directory exists for sure. Tried a lot of logging, don't know what else could help. It fails always with an IO exception and Error-Code = 2

java.io.IOException: Cannot run program "cwebp" (in directory "/tmp/spring_webp_converter_service"): error=2, No such file or directory
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
    at java.base/java.lang.Runtime.exec(Runtime.java:635)
    at java.base/java.lang.Runtime.exec(Runtime.java:459)

Somehow logging output tells me that the directory is writeable and is executable.. Also I can definitely write the source file (the file to convert) and it definitely exists. It's all about the exec-command..

Excerpt of my code:

process = Runtime.getRuntime().exec(execCommand, null, tmpDir);

.travis.yml

language: java

jdk:
  - oraclejdk10

before_install:
  - sudo apt-get update
  - sudo apt-get install -y libwebp-dev

cache:
  directories:
    - $HOME/.m2

Does anyone know how I can get this to work?


Solution

  • I found a working solution to get cwebp (even in the latest version!) into path

    before_script:
      - wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.0.0-linux-x86-64.tar.gz
      - tar -xzf libwebp-1.0.0-linux-x86-64.tar.gz
      - export PATH=$PATH:$PWD/libwebp-1.0.0-linux-x86-64/bin/