Results 1 to 4 of 4
  1. #1
    newbie123 is offline Member
    Join Date
    Nov 2009
    Rep Power

    Question running java under Windows 7

    This may be a Windows 7 problem and have nothing to do with Java ... so let me apologize from the start!

    I have been writing all my Java programs on a Mac. Once the program is compiled, an icon associated with the main class appears. If I click the icon, the program runs swimmingly.

    When I try to run the same program under Windows 7 by clicking on the main class file, Windows 7 asks, "Which program do you want to open the file with?" If I select Java, I get a spinning circle ... kind of like my program going down the toilet ... and the program never runs.

    I can compile and run the program from the command prompt.

    Is there some arcane Windows trick I must employ to get the program to run just by clicking the icon?

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Rep Power


    You may need to set your Window file associations so that class files are associated with java (or is it javaw?). This can be done via the Windows control panel (I think).

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    Can you open a command prompt window and change to the folder with the class file? If so you can then issue the java command:
    java filename (note without the .class extension)

    There is a problem with trying to associate a .class file with a command. You'll need to do some tricks to strip off the .class extension.
    I (just now in fact) wrote a small batch file that strips off the extension. I then associate that batch file with the .class extension:
    Action: C:\Batchfiles\ExecClass.bat "%1"

    REM Execute a java class file - need to strip extension
    echo filename is %~n1
    java %~n1
    If anyone knows a cleaner way to execute a java .class file, please post it.

    If you package your code in a .jar file, there shouldn't be a problem. The jre/jdk install adds an association for the .jar extension.
    Last edited by Norm; 05-29-2010 at 10:34 PM. Reason: correct spelling error

  4. #4
    newbie123 is offline Member
    Join Date
    Nov 2009
    Rep Power

    Default reply to Norm

    I can get things to run just fine using the command:

    java filename (without the .class).

    I play with your batch file and look into the .jar solution.

    Thanks for the quick reply.

Similar Threads

  1. Errors running app in linux but not in Windows
    By JohnST in forum New To Java
    Replies: 3
    Last Post: 03-12-2010, 02:58 AM
  2. java on windows 64
    By JoelOFH in forum New To Java
    Replies: 1
    Last Post: 01-27-2010, 07:27 AM
  3. Java IDE for windows 7
    By Implode in forum New To Java
    Replies: 3
    Last Post: 09-17-2009, 09:16 AM
  4. Replies: 0
    Last Post: 08-26-2009, 02:03 PM
  5. Help with windows in java
    By lenny in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 07:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts