Reputation: 125
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?
Upvotes: 1
Views: 189
Reputation: 475
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"});
Upvotes: 1
Reputation: 1501656
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
.
Upvotes: 2