Results 1 to 8 of 8
  1. #1
    wonstatus is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default Running .jar in command prompt

    I'm a little confused if you can actually do this, I set the program up not using a GUI because it doesn't need one, so I am trying to figure out if I can make the program run in command prompt with user interaction.

    Example: "What is 2+2?"
    User input: "4"
    "Correct!".

    I hope this makes enough sense.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,606
    Rep Power
    23

    Default

    make the program run in command prompt with user interaction
    I think it should work. Have you tried it?
    I've never tried reading from the console from a program in a jar file, so I don't know if it will work.

  3. #3
    wonstatus is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    Yes I have tried, but the .jar wont open. When I open command prompt and test it using "java ProjectName" it runs fine, I just can't get the .jar to open command prompt.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,606
    Rep Power
    23

    Default

    I just can't get the .jar to open command prompt
    how are you executing the jar file?
    Open the command prompt and enter: java -jar JARFILENAME.jar

    Or do you want to display a text field and allow the user to type input into that?

  5. #5
    wonstatus is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    I opened command prompt and typed that in, and it worked, but how would I make it do that when the user opens the .jar file?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,606
    Rep Power
    23

    Default

    It might work if you used a batch file.
    But why stay with command line I/O?
    Write a simple GUI with a text field and a button.

  7. #7
    wonstatus is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    I stayed with the command I/O because I figured at first it would be easier. I will see how it goes with a GUI. Thanks!

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,606
    Rep Power
    23

    Default

    The GUI will be much better.
    There are plenty of sample here on the Forum. Use Search for JFrame or setDefaultCloseOperation for examples

Similar Threads

  1. error in the Command Prompt when running a bat file
    By bluesagemedia in forum New To Java
    Replies: 1
    Last Post: 10-03-2010, 01:05 AM
  2. Compiling/Running in Command Prompt
    By coke_in_a_can in forum New To Java
    Replies: 12
    Last Post: 05-31-2010, 09:05 AM
  3. running command prompt using java
    By xclaim in forum New To Java
    Replies: 1
    Last Post: 01-14-2010, 03:46 AM
  4. Running applet from command prompt
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 03-12-2009, 08:10 AM
  5. problems in running d command prompt commands
    By postaholic066 in forum Advanced Java
    Replies: 1
    Last Post: 09-10-2008, 03:47 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
  •