1
Process process2 = Runtime.getRuntime().exec(new String[]{"javac","-g:vars","/Users/amol/Documents/Java/a.java"});
Process process3 = Runtime.getRuntime().exec(new String[]{"javap","-l","-c","/Users/amol/Documents/Java/a"});

I tried to run this code but I am facing a strange problem. It compiles correctly (means the first line compiles the program) but the second line gives an error saying that 'a' not found. However when I checked the given directory a.class file was created correctly. How should I correctly run the second line?

1
  • I run this code on and it works!!! Commented Jul 4, 2012 at 6:34

2 Answers 2

2

javap takes a class name, not a filename. You probably want to execute:

javap -l -c -classpath /Users/amol/Documents/Java a

(Split that into string arguments appropriately, of course.)

Note that this will still fail if a is in a package - or if the class in a.java isn't actually a at all (which is valid for non-public classes). In both of these cases, you'd need to determine the classes involved, probably by building into an empty directory and finding out which files are produced by javac.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. It worked after adding the classpath argument..:)
1

You may have to specify the classpath argument for javap upto the directory of the class.

Process process3 = Runtime.getRuntime().exec(new String[]{"javap","-l","-c","-classpath  \"/Users/amol/Documents/Java/\"","a"}); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.