简体   繁体   中英

Creating an executable file from java source files, to run on Windows 7

I have some source files written in java on eclipse IDE.
I'm trying to create an executable file so I can run it on Windows 7.
So I tried to export the project from eclipse and it created a jar file, but when I tried to run it from Windows' command prompt (CMD) with "java -jar myapp.jar" it says "java is not recognized as an internal or external command, operable program or batch file."
At this point I found out I don't have the Java Runtime Environment installed on my PC, so I downloaded, installed it, and reboot my computer, and indeed my .jar file changed its icon to java's icon now (nothing happens when double click it), but I still get the above error when trying to run it from CMD.

What am I doing wrong? are there specific settings that I missed when exported the jar file from Eclipse?

You need to add Java to your PATH.

Windows 7

  1. Select Computer from the Start menu
  2. Choose System Properties from the context menu
  3. Click Advanced system settings > Advanced tab
  4. Click on Environment Variables, under System Variables, find PATH, and click on it.
  5. In the Edit windows, modify PATH by adding the location of the class to the value for PATH.
  6. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
  7. Reopen Command prompt window, and run your java code.

By "class" it means the JDK/bin or JRE/bin folder

from: http://www.java.com/en/download/help/path.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM