mardi 21 avril 2015

how to run scala jar file within java file?

Ineed to run scala jar file from java code :

so if I had this scala code:

 object test extends App{
   override def main(args: Array[String]) {
      println("Hello, world! " + args.toList)
    }
  }

and i exported in demo.jar , i want to exceute from inside java application? the way im using it is throw runtime process which not working with me?

import java.io.InputStream;

import org.apache.commons.io.IOUtils;

public class testscalajar{

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try{
            Process proc = Runtime.getRuntime().exec(new String[]{"scala","-cp","d:\\demo.jar", "test"});
         // Then retreive the process output

         InputStream in = proc.getInputStream();
         InputStream err = proc.getErrorStream();
         String inString = IOUtils.toString(in, "UTF8"); 
         String errString = IOUtils.toString(err, "UTF8"); 
       System.out.println(inString);
       System.out.println(errString);
            }
            catch ( Exception e)
            {
                  System.out.println(e.getMessage());
            }

    }

}

any body have any other solutions?????

Aucun commentaire:

Enregistrer un commentaire