问题
I have the following code.
public static void main(String args[]){
ProcessBuilder pb = new ProcessBuilder("java","-xmx768m","DesDatMain","anArgument");
pb.directory(new File("."));
try{
Process process = pb.start();
} catch(IOException e){
e.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable(){public void run(){new JFrame();}});
}
If I run it in “home” folder (containing source files etc.) it will continuously run one app by one app. The same result has executable jar. But if I move this jar to another location it simple runs one window.
Inserted:
Maybe it will be helpful to know that if I have this code:
public static void main(String args[]){
if(args.length==0){
ProcessBuilder pb = new ProcessBuilder("java","-Xmx768m","DesDatMain","anArgument");
pb.directory(new File("."));
try{Process process = pb.start();}
catch(IOException e){e.printStackTrace();}.
System.exit(0);
}
SwingUtilities.invokeLater(new Runnable(){public void run(){new JFrame();}});
}
and it si run either using java.exe or jar file in “home” directory it is normally run but if I move jar to another location no windows is run.
来源:https://stackoverflow.com/questions/34158652/java-continues-application-run