0

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");
}
catch(IOException e1) {System.out.println(e1);}
}
}
1
  • You can edit the question or leave comments to provide additional information. Please do not create answers that don't answer a question. Commented Feb 19, 2011 at 21:03

3 Answers 3

3

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");

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, i try this with eclipse, i have the same error message.
0

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

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

Comments

0

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.

3 Comments

OK, i have the jar file and i try your example.
Thank you i try your example with: java -jar D:\NetBeansProjects\GetIPAddress\dist\GetIPAddress.jar but now i don't have the error message, it's like it runs without any default but i don't see the output of my jar file. there is just : run:BUILD SUCCESSFUL (total time: 1 second) And nothing happens.
Did you do this on a command prompt, or from Netbeans? Do it from the Windows Command prompt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.