Search code examples
javajaribm-cloud

Running a jar in java liberty app on bluemix


I'm using a dialog app in Bluemix, in java. I have another java project, on Elcipse, and to make it simple for me, I decided to turn it into a runnable jar.

So, in my dialog app, I want to run a jar, take the output, and use it. I'm trying to use this, in DemoServlet.java :

            Runtime runtime = Runtime.getRuntime();
            runtime.exec("java -jar SomeCoolApp.jar");

It is really important that I can use the output of this jar only when my users have a specific behavior.

I got an error :

App/0Cannot run program "java": error=2, No such file or directory App/0[ERROR ] Service error: Cannot run program "java": error=2, No such file or directory

I understand that I dont understand at all the logic of bluemix. I need help. This is a part of my bluid.xml :

<property name="LIB_DIR" value="./lib" />
<property name="WEB_INF_LIB_DIR" value="./WebContent/WEB-INF/lib" />
<property name="warname" value="webApp.war" />
<path id="classpathDir">
    <pathelement location="build/bin" />
    <fileset dir="${LIB_DIR}">
        <include name="*.jar" />
    </fileset>
    <fileset dir="${WEB_INF_LIB_DIR}">
        <include name="*.jar" />
    </fileset>
</path>

And in /WebContent/WEB-INF/lib I put my jar, and every jar I need. I never used the cf command line, I didn't change the manifest.yml. I dont know if or how i should modify it. Thank you for your help.


Solution

  • Thanks to Mr Bush from IBM I have the answer. Running a jar in Bluemix is hard - I hope this post will be easy to find.

    ProcessBuilder pb = new ProcessBuilder("/home/vcap/app/.java/jre/bin/java", "-jar", "/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.war/WEB-INF/lib/hello.jar");
    pb.redirectErrorStream(true);
    Process proc = pb.start();
    

    Problem 1: java Path
    Problem 2: jar Path
    Problem 3: Process