JAVA - continues application run

半腔热情 提交于 2019-12-25 03:32:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!