I created a java text based game. I exported it as a runnable jar file in eclipse, but double clicking didn't work to run it (not sure why this is, would appreciate an explanation) so I created a .bat file which has:

java -jar game.jar

This works on some computers. However, when a user who doesn't have java in their PATH (I assume this is the reason) runs the .bat file, it comes up with the error:

java is not recognized as an internal or external command

How can I make my java game able to run on all computers that have java (1.6) installed?

有帮助吗?

解决方案

java -jar <your-jar> is, I think, the best you can do, if you want to support different operating systems as well. If a user doesn't have java command in the path, java support has not been installed as a public JRE and user should either fix the configuration or explicitly specify which private JRE is to be used. Oracle documentation explicitly states about the public JRE that

You must set the PATH environment variable to point to JAVA_HOME\bin (where JAVA_HOME is the location where you installed the public JRE) to register the JRE.

so a user should do just that. You can, however, check if JAVA_HOME is set and if java exists in the path and provide informational error message if it is not.

If you're fine with only supporting windows, you can use various .exe packaging systems to ease the process for end user. See this, this and this thread for details.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top