Page 1 of 2 12 LastLast
Results 1 to 20 of 32
  1. #1
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default Run a Java program on Windows.

    I want to make a Java program that would run on Windows 7. I know you can run .jar files in the command line with the command "java -jar."

    But say I want to make a program that would run by simply double clicking an executable maybe. How would I do this?

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    You can double click the jar file. You can create a bat file and double click that.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    To be able to double click on a jar file and have the java program start with the -jar option requires an entry in the Registry. I think the java installation creates the needed entry.
    Try double clicking on a jar file and see if it starts execution.

  4. #4
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    Ah, I thought so. When I double click a jar file, nothing happens. And I have no idea what to install/change in my registry to get them to run.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    The registry should have been set.
    On XP you can see the command line for a file extension by doing this. No idea on Windows 7
    Open Windows Explorer
    Click on Tools menu
    Click on Folder Options
    Select File Types tab
    Scroll down in the "Registered file types:" list until you see an entry for JAR.
    Select the JAR entry.
    Click the Advanced button
    In the Edit File Type window scroll down the list of Actions until you see the one in bold.
    Select the bold one
    Click the Edit button
    Select, Copy and paste here what is in the "Application used to perform action:" window.

    Be careful not to change anything and Cancel your way out of the open windows.


    Here's the contents of my Registry for a jar file default action:
    D:\Java\jre6_10\bin\javaw.exe -Xmx256M -jar "%1"


    What happens if you open a command prompt window, change to the folder with the jar file and enter:
    java -jar <THE JAR FILENAME HERE>.jar

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    As far as I am aware there is no need to fanny about in the Registry. If your jar file doesn't work then you probably made a mistake or skipped a step when creating it. Did you use a manifest file? Is the manifest file correct?

  7. #7
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    What happens if you open a command prompt window, change to the folder with the jar file and enter:
    java -jar <THE JAR FILENAME HERE>.jar
    The program runs fine just as it did in Netbeans. I don't have a file types tab when I open folder options, but I opened file associations and .jar files are set to javaw.exe.

    Quote Originally Posted by Junky View Post
    As far as I am aware there is no need to fanny about in the Registry. If your jar file doesn't work then you probably made a mistake or skipped a step when creating it. Did you use a manifest file? Is the manifest file correct?
    I pressed the clean/build button on Nebteans and it creates one.
    Last edited by a_programmer; 07-15-2011 at 03:38 AM.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    file associations and .jar files are set to javaw.exe.
    You need to have the -jar option on the command line. It needs to look something like this:

    D:\Java\jre6_10\bin\javaw.exe -Xmx256M -jar "%1"


    I don't know what the file associations is. You need to be able to specify a full command line like I showed.

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Extract the manifest file from the jar. Open it and make sure it actually contains the correct information.

  10. #10
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    Not sure what the correct information is.

    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.8.1
    Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)
    Main-Class: calc.Main
    Class-Path:
    X-COMMENT: Main-Class will be added automatically by build
    In the .jar file, the main class is actually "Main.class". Maybe that's the problem? Also, should Class-Path have something there?

  11. #11
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    It is looking for the Main class in the calc directory. Does your jar file have this directory? Also make sure there is a carriage return on the last line.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    If you are able to execute the jar file in a command prompt with this command:
    java -jar <FILENAME>.jar

    Then the manifest file must be ok.

    Main-Class: calc.Main
    Your class is named Main and is in the package: calc

  13. #13
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    You need to have the -jar option on the command line. It needs to look something like this:

    D:\Java\jre6_10\bin\javaw.exe -Xmx256M -jar "%1"


    I don't know what the file associations is. You need to be able to specify a full command line like I showed.
    File associations is a program on Windows 7 showing all the file associations. Where do I find the "D:\Java\jre6_10\bin\javaw.exe -Xmx256M -jar "%1" thing? I searched the registry for javaw and "(Default)" and "IsHostApp" came up. Both have nothing in them when I open them up.

    Quote Originally Posted by Junky View Post
    It is looking for the Main class in the calc directory. Does your jar file have this directory? Also make sure there is a carriage return on the last line.
    Yes it does. And running it in the command prompt with java -jar works fine.

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Where do I find the "D:\Java\jre6_10\bin\javaw.exe -Xmx256M -jar "%1" thing?
    I gave you the steps in post#5. However MS is always moving and hiding things so I have no idea where to look on Windows 7.

    If you're real brave, I could tell you how to use the registry editor program: regedit.
    The problem with using that tool, if you mess up, the Windows system may have to be re installed.

  15. #15
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    This may be a Windows 7 quirk as Jar files run fine on XP. Try the advice in reply #10 of this thread

    how to open jar files in windows 7

  16. #16
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    I'm brave enough. Just need to know what to search for and what to change.

  17. #17
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    This may be a Windows 7 quirk as Jar files run fine on XP. Try the advice in reply #10 of this thread

    how to open jar files in windows 7
    Can't, Windows 7 only has the General, View, and Search tabs in Folder Options.

  18. #18
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Keep on googling then. This problem has obviously been encountered before and someone must have posted a solution.

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    First we need to see what is in your registry.
    Start the regedit program: either from the Start/Run... command line or by openning a command prompt window
    The left column of the Registry Editor shows a tree structure like Windows Explorer with My Computer at the top
    Close all the sub trees (click on - in square to get +) so there are only about 5 subtrees shown.
    Open the top one: HKEY_CLASSES_ROOT. You will get a LONG list of all the .extensions the OS knows about.
    Scroll down the list to the .jar entry and click on it. The folder should change shape to show an open folder
    The right hand window will have one (or more?) lines starting with (Default) in Name column and jarfile in the Data column
    The Data column could be different. Write it down as that is the address of our next stop.
    Scroll down more in the left column until you get to the jarfile (or what ever was in your Data column) entry.
    Click on the folder for jarfile to select it.
    Go to the File menu and Click on "Export"
    Save the file to jarfile.reg in a location where you can find it later.
    Exit regedit.

    Rightclick the .reg file, select Edit and Copy and paste the exported file here.

    Mine looked like this:
    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\jarfile]
    @="Executable Jar File"

    [HKEY_CLASSES_ROOT\jarfile\shell]

    [HKEY_CLASSES_ROOT\jarfile\shell\open]

    [HKEY_CLASSES_ROOT\jarfile\shell\open\command]
    @="\"D:\\Java\\jre6_20\\bin\\javaw.exe\" -jar \"%1\" %*"

    Notice the bottom line. It is very similiar to the one I posted earlier.

    Don't change anything. The saves are immediate and can be very bad.

  20. #20
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Keep on googling then. This problem has obviously been encountered before and someone must have posted a solution.
    I've been googling, just haven't found an answer yet. But I'm still looking. I'll post the solution here once I figure it out.

    Here's what I have as my jarfile value: "C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*

Page 1 of 2 12 LastLast

Similar Threads

  1. One program for both Windows and Linux
    By satimis in forum New To Java
    Replies: 8
    Last Post: 04-12-2010, 10:49 AM
  2. Replies: 3
    Last Post: 08-10-2009, 07:34 AM
  3. Executing java program using windows scheduler
    By kanitha in forum New To Java
    Replies: 0
    Last Post: 03-21-2009, 10:16 AM
  4. Replies: 5
    Last Post: 03-20-2009, 11:04 PM
  5. Replies: 1
    Last Post: 01-16-2009, 11:15 PM

Posting Permissions

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