Using Java Runtime class to find out a class in Jar file in Unix -


i using java runtime class write program checks class file in list of jar files. here program:

import java.io.*;  public class javaruncommand {      public static void main(string args[]) {          string s = null;          try {              process p = runtime.getruntime().exec("find /home/user/lib/ -name \"*.jar\" | xargs grep myclass.class");              bufferedreader stdinput = new bufferedreader(new                  inputstreamreader(p.getinputstream()));              bufferedreader stderror = new bufferedreader(new                  inputstreamreader(p.geterrorstream()));              // read output command             system.out.println("here standard output of command:\n");             while ((s = stdinput.readline()) != null) {                 system.out.println(s);             }              // read errors attempted command             system.out.println("here standard error of command (if any):\n");             while ((s = stderror.readline()) != null) {                 system.out.println(s);             }              system.exit(0);         }         catch (ioexception e) {             system.out.println("exception..");             e.printstacktrace();             system.exit(-1);         }     } } 

when run program getting error message as:

here standard output of command:  here standard error of command (if any):  **find: paths must precede expression: | usage: find [-h] [-l] [-p] [-olevel] [-d help|tree|search|stat|rates|opt|exec] [path...] [expression]** 

please me missing in code, if directly run command find /home/user/lib/ -name \"*.jar\" | xargs grep myclass.class"); on unix command line working fine.

also, if replace expression below line java code working fine.

process p1 = runtime.getruntime().exec(new string[] { "/bin/sh", "-c", "cd /home/user/lib/ && find . -name \"*.jar\" | xargs grep myclass.class" }); 

process p = runtime.getruntime().exec("find /home/user/lib/ -name \"*.jar"); 

change to

process p = runtime.getruntime().exec("sh -c find /home/user/lib/ -name \"*.jar"); 

so shell gets involved , expands wildcard.

but don't need run find here, files.listfiles() called recursively.

i'd interested see you're doing next well. defining urlclassloader initialized list of jars , using try load class, rather unzipping jars myself.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -