Open jar file with cmd

27,362

Sounds like your PATH env. variable doesn't have Java in it. You can add it by following Oracle's tutorial

Adding Java to your PATH Environment variable.

Usually it's something like ;C:\Program Files\Java\jre7\bin

To your second question - yes it's possible.
Open up notepad, then type java -jar adventure.jar then save it as launch.bat or something. then you are able to double click that batch file, which will run your java archive.

Share:
27,362
russellsayshi
Author by

russellsayshi

Updated on December 01, 2020

Comments

  • russellsayshi
    russellsayshi over 3 years

    I have a jar file named "adventure.jar". When you run it through the cmd with java -jar adventure.jar it works fine. However, I am testing opening the file on a new computer, and I am encountering a problem. This computer doesn't have the java command in the command prompt. It defiantly has Java installed, but maybe just not the JDK? Anyway, my goal is to make the jar file run from cmd when double clicked, without the need of commands (is that even possible?). The jar is already executable, but it doesn't execute from the command prompt like I need. Any help would be appreciated.

    EDIT: If there is a way to do this through an exe or batch file I'd be fine with that, too.

  • russellsayshi
    russellsayshi over 11 years
    Thanks for your answer! However, I can't modify the computer that I've loaded the jar file on (like the path) because I am trying to make this distributable, where anyone can double click the jar and it runs. On the second part of your answer, you use the java command, and that's the impossible part for me. I already tried making batch files, but this computer doesn't have that command. If you type 'java' it says it's not a recognizable command. I know it has Java though, I am able to run applets, Java programs, and enter the Java control panel. Is it a problem with the computer?
  • russellsayshi
    russellsayshi over 11 years
    Thanks, but I can't modify the computer that has the jar, because my goal is to be able to distribute the jar so anyone can just double click on it.
  • ddavison
    ddavison over 11 years
    If you can't modify that computer, then what you can do is on the first line of your batch file, type - PATH=%PATH%;C:\Program Files\Java\jre7\bin or wherever your java is installed. That means "for this program i want to include anything under \bin. Which includes the java executable.
  • BenjiWiebe
    BenjiWiebe over 11 years
    Well, on most or all Windows machines, .jar files will start automatically when double clicked, because java setup installs a registry key that tells Windows to open .jar files with java.exe.