how to launch java file with ProcessBuilder?
hi,
i try to run java program with ProcessBuilder
but it works only with .exe file and with .jar or .java
i use netbeans 6.9
why please?
import java.io.*;
public class Mani
{
public static void main(String args[])
throws IOException, InterruptedException
{
try
{
Process p=Runtime.getRuntime().exec("javaw -jar D:\\NetBeansProjects\\GetIPAddress\\dist\\GetIPAddress.jar");
}
catch(IOException e1) {System.out.println(e1);}
}
}
Neversleepin
Junior Poster in Training
72 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
I think the problem is:
1- i install java on my pc.
2- i install NetBeans 6.9
but i never i try javac on cmd
i always use netbeans for testing my code.
but today when i try to type "javac" on cmd it's not working, it doesn't recognize javac as an internal command.
how could resolve this problem on first?
thank you
Neversleepin
Junior Poster in Training
72 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
no, no, not, please which OS (but I just something ..... about HP, As400 and Win platforms)
sure this way (via Runtime) you can run compiled Java aplication, but why
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
So could you explain to me why my code is not working?
i'm beginner in java.
with the same code if i try to execute .exe file like calc.exe it's working!
thank you
Neversleepin
Junior Poster in Training
72 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
again, for which OS (Windows or ....), because command & path is so different for various Native OS
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
Neversleepin
Junior Poster in Training
72 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
So my java is located here:
C:\Programmes\Java\jdk1.6.0_17
C:\Prpgrammes\Java\jr6
And i set path like this:
ClassPath is:
.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip
JAVA_HOME is:
C:\Progammes\Java\jdk1.6.0_17
PATH is:
C:\Program Files\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\Common Files\Autodesk Shared;C:\Program Files\Windows Live\Shared;C:\Program Files\QuickTime\QTSystem\;set path=%path%;C:\Progammes\Java\jdk1.6.0_17\bin%JAVAHOME%\bin
I'm not sure about my setting for java.
i know one thing is that javac is located in C:\Programmes\Java\jdk1.6.0-17
and when i click it it's working but not from cmd windows
Thank you
Neversleepin
Junior Poster in Training
72 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
Process p = Runtime.getRuntime().exec("cmd /c start java -jar D:\\NetBeansProjects\\GetIPAddress\\dist\\GetIPAddress.jar");
but why not run java from ShortCut (f.e. from DescTop)
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
In fact hwen i try to run the jar file only, it's not working
there is an error message :
Could not find the main class: getipaddress.GetIPAdress.Program will exit
Maybe my jar is not created correctly by netbeans
i don't know
Neversleepin
Junior Poster in Training
72 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
if you are sets main class correctly, then works,
check the project properties
I'll use this one only if FatalError raised, why run java from Runtime.getRuntime().exec(...
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224