开发者

how to launch java file program with processbuilder?

here i'm trying to launch a java program inside another java program. after some search in the forum i found some clues but my code launches only .exe file and not .java file why?

import java.io.*;

public class Mana
{
public static void main(String args[])
        throws IOException, InterruptedException
{
try
{
Process p=Runtime.getRuntime().exec(" D:\\NetBeansProjects\\GetIPAddress\\dist\\GetIPAddress.jar")开发者_如何学Python;
}
catch(IOException e1) {System.out.println(e1);}
}
}


for java file you must run javaw.exe(not java, because java.exe shows new console window) from jre:

Process p=Runtime.getRuntime().exec("javaw -jar D:\\NetBeansProjects\\GetIPAddress\\dist\\GetIPAddress.jar");


If you are ok to use 3rd party library, you can use:

http://code.google.com/p/jlibs/wiki/JavaProcessBuilder


Okay, looks like you have several problems.

First, to call a java program as a jar file, you need to have the jar file. Your question first looked like you already had one (producted by Netbeans). So try this:

java -jar D:\NetBeansProjects\GetIPAddress\dist\GetIPAddress.jar

in a console window (cmd.exe on Windows). If this works, then your call as given by Sergey should work too. If it does not work, then you have to look at how to create this jar file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜