process - How can I use java code to compile java file in other folder? -
i trying use java's
process p = runtime.getruntime().exec(command);
to compile .java files in other folder, not work.
main.class in folder a, , .java files in folder a/test.
main.class :
public class main{ public static void main( string[] args ) throws ioexception,interruptedexception{ string line =""; string command = "javac test/*.java"; process pro = runtime.getruntime().exec(command); bufferedreader in = new bufferedreader( new inputstreamreader( pro.getinputstream())); while ((line = in.readline()) != null) { system.out.println(line); } bufferedreader er = new bufferedreader( new inputstreamreader( pro.geterrorstream())); while ((line = er.readline()) != null) { system.out.println(line); } } }
and error stream shows:
javac: file not found: test/*.java
why happen? there java file in folder test
in case java doesn't work * wildcard, shell. means transform * -> list of file_names manually , exec() every particular file.
also aware on classpath. if run class form ide, classpath different expect (same folder in class placed).
Comments
Post a Comment