Ky6000
Ky6000

Reputation: 103

Java - No such file or directory

I have been trying to get this program to run a class file that is located in /Library/Application Support/Adobe/Adobe PCD/cache/Main.class.

Yet every time I run the method below, It cannot find the file specified. I think that eclipse is looking for the file path above in the project folder. But the first command doesn't seem to work. Can Anyone help me? Is there another way to run the class file?

static Runtime r = Runtime.getRuntime();

public static void Run() {

      try {
       Runtime rt = Runtime.getRuntime();
       String run = "/Library/Application Support/Adobe/Adobe PCD/cache/";    
       String[] command = {"java -cp " + run, "java Main"};
       Process pr = rt.exec(command);

       BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

       String line=null;

       while((line=input.readLine()) != null) {
           System.out.println(line);
       }

       int exitVal = pr.waitFor();
       System.out.println("Exited with error code "+exitVal);

   } catch(Exception e) {
       System.out.println(e.toString());
       e.printStackTrace();
   }
}

Upvotes: 0

Views: 953

Answers (1)

Eric Jablow
Eric Jablow

Reputation: 7889

This tries to run a mythical program java -cp /Library/Application Support/Adobe/Adobe PCD/cache/ with argument java Main. java Main is an illegal name for a class too. Instead, have your command array be:

String[] command = {"java", "-cp", run, "Main"};

However, unless you have a Main class in the default package, simply add the run directory to your application's class path, and then call Main.main(), possibly playing games with standard input and output. There is no need to start a second JVM. Or, figure out what Main does, and call the classes it calls. Is there Javadoc for the Adobe code?

When the Ant task <zip> runs, Ant does not start a new VM or a command-line zip utility. Instead, the task's class calls methods in java.util.zip. You should do something similar.

Upvotes: 1

Related Questions