0

So, I am trying to run a program from jar files. It uses javaswing and has a gui.

The program runs fine in netbeans and in eclipse.

When I try to run it from the exported jar file it says this:

Unable To Install Java There are errors in the following switches: "C:\Users\CNC Department\Desktop\ValveConversion.jar";.

Check that the commands are valid and try again.[java installation not complete Now, I also tried doing it from the command prompt. Here is what came up: [cmd prompt attempt][1] [1]: https://i.stack.imgur.com/7reZ3.png

So, I reinstalled the java JDK, java SDK, netbeans and eclipse. The issue is still occurring in both command prompt and from running the jar file directly.

What am I doing incorrectly here? What do you recommend that I do to get this to run from a .jar file?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • You need to set the JAVA_HOME environment variable – LppEdd Mar 08 '19 at 18:26
  • To run commands (.exe files) their location need to be in `path` system variable. – Pshemo Mar 08 '19 at 18:32
  • Take a look at [Environment variables for java installation](https://stackoverflow.com/q/1672281). – Pshemo Mar 08 '19 at 18:34
  • Pshemo, I tried it, https://imgur.com/a/dlKmnBP –  Mar 08 '19 at 18:37
  • Lppedd and Pshemo, So, I followed pshemo's guide. https://imgur.com/a/QBCI24K Here is my present configuration. –  Mar 08 '19 at 18:42
  • I added this in uservariables to just to be sure, https://imgur.com/a/qyu1gSI –  Mar 08 '19 at 18:46
  • Same message when I attempt it in command prompt. –  Mar 08 '19 at 18:46
  • If you don't want to set a PATH var you can always execute it as follows: `C:\Downloads/Software/jdk1.8.0_112/bin/java -jar C:\Users\CNC Department\Desktop\ValveConversion.jar` – Roberto Manfreda Mar 08 '19 at 18:46
  • I feel like I am missing something here. PS, I tried your cmd input Roberto Manfreda https://imgur.com/a/Wg4olVn –  Mar 08 '19 at 18:51
  • This was an example... you have to modify that path with the path of your downloaded jdk if you have any! – Roberto Manfreda Mar 08 '19 at 18:53
  • Shoot thanks. I figured that out after the fact. It ended up giving me this new error. I think we're getting closer. https://imgur.com/a/tAUsjmU –  Mar 08 '19 at 18:55
  • Please wrap the path with double quotes. Beacuse in your path are some white spaces. Or escape the white spaces if you don't want to wrap strings. `C:\Downloads/Software/jdk1.8.0_112/bin/java -jar "C:\Users\CNC Department\Desktop\ValveConversion.jar"` – Roberto Manfreda Mar 08 '19 at 19:00
  • Roberto Manfreda, thank you so much! You rock! Success! https://imgur.com/a/r16WcXF –  Mar 08 '19 at 19:07
  • Yes but is better if you set the PATH running this from a cmd (with elevated privileges): `setx JAVA_HOME -m "C:\Program Files\Java\jdk-11.0.2"`then restart cmd and run `where java` and `java -version` just to be sure that it's all ok. Now you can use the java command just calling `java` – Roberto Manfreda Mar 08 '19 at 19:50

1 Answers1

0

You need to set the java path
Open a cmd with elevated privileges and run this command to set the JAVA_HOME environment variable using setx command:

setx JAVA_HOME -m "C:\Program Files\Java\jdk-11.0.2"

Then restart the cmd and run java -version to check if it's all ok.
For reference setx command documentation

Or simply use the following snippet if you prefer to use java without setting the PATH variable:

"C:\Program Files\Java\jdk-11.0.2\bin\java" -jar "C:\Users\CNC Department\Desktop\ValveConversion.jar"
Roberto Manfreda
  • 2,345
  • 3
  • 25
  • 39