Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: stand alone

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default stand alone

    the program in question runs well. my question is how to make it a standalone. i use BlueJ. help please.
    its a simple guessing game. here's the code
    import java.util.Scanner;
    public class GuessingGameV1
    {
        public static void main(String[]args)
        {
            Scanner in = new Scanner(System.in);
            int playagain = 1;
            while(playagain ==1)
            {
                System.out.print("\u000C");
                System.out.println("i want to play a game, lets play a gusseing game");
                System.out.println("i will pick a number between 1 and 100");
                System.out.println(" you guess the number, i will tell you if your guess is too high or too low");
                System.out.println("BEGIN");
                int randomnumber =(int) (Math.random()*100 - 1) + 1;
                int guessednumber =  0;
                while ( guessednumber != randomnumber)
                {
                    System.out.println("Guess a number");
                    guessednumber = in.nextInt();
                    if (guessednumber > randomnumber)
                    {
                        System.out.println("Too High");
                    }
                    else if (guessednumber < randomnumber)
                    {
                        System.out.println("Too Low");
                    }
                    else if (guessednumber == randomnumber)
                    {
                        System.out.println("WINNER WINNER CHICKEN DINNER");
                        System.out.println("enter the number one to play again , any other to quit");
                        playagain = in.nextInt();
                    }
                }
            }
        }
    }

    p.s, how do i post to different threads? i can only get to 'whats wrong with my code'.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: stand alone

    What do you mean by "standalone"? Do you mean run it outside of the IDE? If so, do some research on how to package it in a jar file. Since your program is command-line dependent (meaning: it doesn't have a GUI), the jar file will need to be executed from a command-line, instead of by double-clicking the jar, because the command prompt window doesn't automatically pop up when you double-click a jar file.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    yes that's what i mean. i've already run it from command prompt. it didn't do anything. i can put it into an executable jar file.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    it didn't do anything
    What problems are you having? Were there error messages? copy the full text and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    i figured it out. i had to change a setting. sorry. but i still have a question about it. is there a way i can run it just by double clicking it?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    a way i can run it just by double clicking it
    The OS should be setup to use the java -jar command when a jar file is double clicked.
    What OS are you on?
    Do you have a JRE installed?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    windows 7 home premium. i do.it does nothing when double clicked

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    To see if there are any errors, open a command prompt window, change to the directory with the jar file and enter: java -jar THEJARFILENAME.jar
    Copy the full contents of the window and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: stand alone

    On a sidenote. After installing Java I was able to open .jar files with a double click on windows 7, but after running a java webstart app once the settings were changed and .jar files were opened with java webstart by default (which obviously doesnt work) until I changed it back manually. I do not know why the defaults are changed in such a way, but its definitely not helpful.
    This same problem might also have happened here.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    I've often had problems with java installs walking over my existing registry entries. I found a quick workaround that allows me to restore my entries after some product changed some of the registry. I create a new entry that holds all the commands by appending my initials to the existing name: jarfileXXX and then changed the .jar entry to point to my new entry. When Product installs change .jar and jarfile, I change .jar to point to my jarfileXXX and merge what is in jarfile into jarfileXXX
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    when i run it in command prompt it runs perfectly. ill still post it though... but i cant seem to copy text from cmd?
    but it works exactly the way i intended it to.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    If you can manually execute it, it could be the OS's registry entry for executing it is messed up.
    to copy text from cmd
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    here it is.


    C:\Users\Pookie>cd desktop

    C:\Users\Pookie\Desktop>java -jar guess.jar
    ♀i want to play a game, lets play a gusseing game
    i will pick a number between 1 and 100
    you guess the number, i will tell you if your guess is too high or too low
    BEGIN
    Guess a number
    50
    Too High
    Guess a number
    25
    Too High
    Guess a number
    10
    Too High
    Guess a number
    5
    Too High
    Guess a number
    2
    Too Low
    Guess a number
    3
    Too Low
    Guess a number
    4
    WINNER WINNER CHICKEN DINNER
    enter the number one to play again , any other to quit
    3

    C:\Users\Pookie\Desktop>

    dont judge me. for whatever reason my mom named the computer 'pookie'
    ♀<---- also, that is different in bluej. its
    System.out.print("\u000C");
    wich in bluej, clears the terminal window, its only for neatness.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    Do you know how to see what commandline the OS uses when you double click on a file?
    Win7 has an interface to associate extensions with commands. It doesn't work on my system. I use the regedit program to view and modify the registry.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    start>computer>system properties>advanced system properties>environment variables>System variables> path.
    i have it set so it should know what to do with jar and java files
    C:\Program Files\Java\jdk1.7.0_25\bin;
    is the first thing.

    other than that, no i dont know what it uses or how to find it.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    it should know what to do with jar
    The Environment variable: PATH is used to find a command file like: java.exe. It doesn't associate a command line with a filetype like: jar.
    The registry has an entry for .jar file which refers to another section of the registry where there is the command line to be used to open that type of file.

    Editing the registry can cause damage to the running of the OS. It shouldn't be done casually.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    i didnt do it casually. had it been my computer, i wouldve been casual.but its my moms computer, so i took the time to do the research on changing/adding path. so i need to find a path entry for jar?

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    find a path entry for jar
    It's not called a path entry. There are entries in the registry for all the file extensions that the OS knows about. Associated with each extension is a list of command lines that can be used to open that file type. If you right click on a file, the names of the entries are displayed in a list allowing you to chose what command line to use to execute a file. For example I have over 4 entries for a jar file on my Win7 system.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    when i right click on a file im not seeing any command lines.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    You don't see the commandline, you should see the name associated with a commandline. If you look in the registry for that type of file you will see the list of names with their commandlines.

    Here is an export of the jarfile entry for one of my PCs:
    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\jarfile_XXX]
    @="Executable Jar File"
    "EditFlags"=dword:00000000
    "BrowserFlags"=dword:00000008

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell]
    @="Java_6_10"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Append_filenam e_to_CB]
    "EditFlags"=hex:01,00,00,00
    @="Append path to CB"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Append_filenam e_to_CB\command]
    @="javaw.exe -jar D:\\JavaDevelopment\\runtime\\CopyToCB.jar -append \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Check_Referenc es]
    "EditFlags"=hex:01,00,00,00
    @="Check References"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Check_Referenc es\command]
    @="java.exe -cp D:\\JavaDevelopment\\runtime\\CheckClassRefs.jar;. CheckClassRefs -jar \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Copy_path_to_C B]
    "EditFlags"=hex:01,00,00,00
    @="Copy path to CB"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Copy_path_to_C B\command]
    @="javaw.exe -jar D:\\JavaDevelopment\\runtime\\CopyToCB.jar \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_j ava_1.6.0]
    @="Execute with java 1.6.0"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_j ava_1.6.0\command]
    @="D:\\Java\\jre1.6.0_02\\bin\\java.exe -Xmx128M -jar \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_j ava_1.6.0\ddeexec]

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_j ava_1.6.0\ddeexec\Application]
    @="java"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_j ava_1.6.0\ddeexec\Topic]
    @="System"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_j re_1.4.1]
    @="Execute with jre 1.4.1"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_j re_1.4.1\command]
    @="C:\\BatchFiles\\Execjre141.bat \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_J RE_1.5]
    @="Execute with JRE 1.5"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_J RE_1.5\command]
    @="C:\\BatchFiles\\Execjre15.bat \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_w indow]
    @="Execute with window"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_w indow\command]
    @="E:\\Java\\jdk1.5.0_04\\bin\\java.exe -jar \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_w indow\ddeexec]

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_w indow\ddeexec\Application]
    @="java"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Execute_with_w indow\ddeexec\Topic]
    @="System"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Exec_wihth_1.6 _&_window]
    @="Exec with 1.6 & window"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Exec_wihth_1.6 _&_window\command]
    @="C:\\BatchFiles\\Java6WithWindow.bat -jar \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Exec_wihth_1.6 _&_window\ddeexec]

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Exec_wihth_1.6 _&_window\ddeexec\Application]
    @="Java6WithWindow"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Exec_wihth_1.6 _&_window\ddeexec\Topic]
    @="System"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Java_6_10]
    @="Java 6_10"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Java_6_10\comm and]
    @="D:\\Java\\jre6_10\\bin\\java.exe -Xmx128M -jar \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Java_6_10\ddee xec]

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Java_6_10\ddee xec\Application]
    @="java"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Java_6_10\ddee xec\Topic]
    @="System"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\open]

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\open\command]
    @="\"C:\\Program Files\\Java\\jre1.5.0_04\\bin\\javaw.exe\" -jar \"%1\" %*"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_in_WinZip]
    "EditFlags"=hex:01,00,00,00
    @="Open in WinZip"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_in_WinZip \command]
    @="\"C:\\Program Files\\WinZip\\WINZIP32.EXE\" \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_w/o_window_Java_6_10]
    @="Open w/o window Java 6_10"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_w/o_window_Java_6_10\command]
    @="D:\\Java\\jre6_10\\bin\\javaw.exe -Xmx128M -jar \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_w/o_window_Java_6_10\ddeexec]

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_w/o_window_Java_6_10\ddeexec\Application]
    @="java"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_w/o_window_Java_6_10\ddeexec\Topic]
    @="System"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_with_wind ow]
    @="Open with -wrtCons"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_with_wind ow\command]
    @="java.exe -jar \"%1\" -wrtCons"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_with_wind ow\ddeexec]

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_with_wind ow\ddeexec\Application]
    @="java"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Open_with_wind ow\ddeexec\Topic]
    @="System"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Show_class_ver sions]
    @="Show class versions"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Show_class_ver sions\command]
    @="java.exe -cp D:\\JavaDevelopment\\NormsDev ShowVersions \"%1\" "

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Show_class_ver sions\ddeexec]

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Show_class_ver sions\ddeexec\Application]
    @="java"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Show_class_ver sions\ddeexec\Topic]
    @="System"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Show_Entries]
    "EditFlags"=hex:01,00,00,00
    @="Show Entries"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Show_Entries\c ommand]
    @="C:\\BatchFiles\\JarEntries.bat \"%1\""

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Start_for_JCon sole]
    @="Start for JConsole"

    [HKEY_CLASSES_ROOT\jarfile_XXX\shell\Start_for_JCon sole\command]
    @="C:\\BatchFiles\\StartForJConsole.bat \"%1\""

    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    thats... confusing. im not sure exactly what that means. i just want to know how to run an executable jar file by double clicking. or is that it?

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    There needs to be an entry in the registry that gives the OS a commandline to execute when a file is double clicked.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    assuming its not there because of lack of response after double clicking the file... how might one fix that?

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stand alone

    It is possible to change the registry by using the regedit program. It is possible to view the registry without making changes to it.
    Open regedit, find the ".jar" entry, open that entry and then find the entry it refers to (often: jarfile)
    open that entry and export it to a .reg file. Rename that file by appending a .txt and it will be safe to edit for copying here.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Apr 2014
    Posts
    19
    My Mood
    Stressed
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: stand alone

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\.jar]
    @="jarfile"
    thats all?

Page 1 of 2 12 LastLast

Similar Threads

  1. Hot Dog Stand Code
    By Powerbomb in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 26th, 2013, 11:45 PM
  2. Stand Alone Classes
    By Andrew R in forum Java Theory & Questions
    Replies: 4
    Last Post: August 18th, 2013, 08:04 PM
  3. How to make an Eclipse program stand alone and more
    By TheBigWif in forum Java Theory & Questions
    Replies: 3
    Last Post: July 30th, 2013, 05:35 PM
  4. Replies: 2
    Last Post: October 14th, 2009, 10:10 AM