Search code examples
androidjarprocessbuilder

Android SDK: execute external jar


I'm trying to execute an external .jar file in my Android SDK project this way:

ProcessBuilder pb = new ProcessBuilder("java.exe", "-jar", "C:/apache-tomcat-7.0.27/BlattA/src/viewer.jar");
        Process process = pb.start();
        InputStream is = process.getInputStream();

        byte[] bytes = IOUtils.toByteArray(is);

when I execute it in any other Java EE project it works perfectly, but in the Android app I get the error: enter image description here

what's the cause and how can I fix it?


Solution

  • That is not possible at all!

    Android is some kind of a special linux and does not support any windows features like the execution of exe files. About the jar file on Android is a hole other bytecode (dalvik VM) so you can also not run a jar file without converting it to a so called dex file. You can also not access the ressources from your pc from your phone with a simple file access.

    Even if you would dex that jar or grep it somehow over the air or by adding that jar as libary this won't work bacause on Android is no Swing or another common UI framework from a desktop system.

    What you can do is to look at the source code of the jar file e.g. from the homepage if that is a open source project and understand how that works. Than you can implement a new Android app which does that job you want to have. But that is quiet much more work than you meight think now.