I have a Calculator.jar file that I created with Netbeans.
I want to run that jar file using java code. After looking around stackoverflow and some documentation sites, I tried the following:
public static void main (String [] args){
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("java -jar C:\\pathToJar\\Calculator.jar);
pr.waitFor();
}
The code runs fine, but my problem comes in with the path to the file. If I run the program without the absolute path, it runs and finishes, but I never see the calculator GUI pop up. When I run with the absolute path, the GUI pops up as expected.
I have the jar file in the same place as my source code. I thought doing that would allow me to just have to put Calculator.jar without the absolute path. That doesn't seem to work though.
Does anyone know how I could possibly store the jar file so I don't need to use the absolute path?
Edit:
I also tried creating a separate package within the project called jarFiles and tried the path jarFiles\Calculator.jar. That didn't work either. I think I'm misunderstanding something about the default path/what path cmd is using by default when I call the command. I'm not sure though.
Thanks for any advice in advance!