Results 1 to 8 of 8
Like Tree2Likes
  • 2 Post By JosAH

Thread: Project Runs Fine in Netbeans but does not display anything in command prompt

  1. #1
    Chronic788 is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Project Runs Fine in Netbeans but does not display anything in command prompt

    Hey guys,

    Little problem here. Hope you can help. The problem is that when I run my program using the command prompt it does not do or display anything.

    Here is an dumbed down version of my code:

    Java Code:
    public class Test {
       
        public static void main(String[] args) {
       
        new Test();
        
    }
        
    public Test(){
        
        printMessage();
        
    }
    
    public void printMessage(){
        
        System.out.println("Hello");
    }
    }
    Code was written and compiled with netbeans. When I type in command prompt:

    <pathname>>Test.jar

    it just goes immediately back to

    <pathname>

    and does not display "Hello".

    Any help or pointers would be appreciated.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Project Runs Fine in Netbeans but does not display anything in command prompt

    When I type in command prompt:

    <pathname>>Test.jar

    it just goes immediately back to

    <pathname>
    That's odd. I would have expected a message along the lines of

    C:\Users\Name>Test.jar
    'Test.jar' is not recognized as an internal or external command,
    operable program or batch file.

  3. #3
    Chronic788 is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: Project Runs Fine in Netbeans but does not display anything in command prompt

    That's odd. I would have expected a message along the lines of

    C:\Users\Name>Test.jar
    'Test.jar' is not recognized as an internal or external command,
    operable program or batch file.
    Well, my gut feeling is that it is running the .jar file fine but it is not displaying the text for some other reason.

    This project is due tomorrow afternoon! Need some answers!

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Project Runs Fine in Netbeans but does not display anything in command prompt

    Quote Originally Posted by Chronic788 View Post
    When I type in command prompt:

    <pathname>>Test.jar
    Is that EXACTLY what you typed?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Project Runs Fine in Netbeans but does not display anything in command prompt

    I agree with DarrylBurke. It's quite difficult to try and diagnose a problem without knowing exactly what the problem is.

    I'll add to his question ("What did you type to run the jar?") another: how did you obtain the .jar archive?

    If you used Netbeans, then we need to know the various settings you used. Better, I think, to (1) compile the program, (2) create the .jar archive and (3) run it all from the command line. That way you can post exactly the three commands you are using.

    -----

    I haven't come across .jar archives being executable by typing their name at the command line. That could just be me, though.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: Project Runs Fine in Netbeans but does not display anything in command prompt

    I just checked: the MS Windows shell (cmd.exe) accepts any file name (plus extension) as a runnable file; it simply runs the file by using the association. The association tells to run it with javaw.exe and that explains why the OP doesn't see anything (the existing shell window isn't 'borrowed' by javaw.exe).

    kind regards,

    Jos
    DarrylBurke and pbrockway2 like this.
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Project Runs Fine in Netbeans but does not display anything in command prompt

    Learn something new every day...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Project Runs Fine in Netbeans but does not display anything in command prompt

    Thanks Jos.

    @OP: you might try using java.exe instead of javaw.exe. Ie something like
    Java Code:
    ???>java -jar Test.jar
    To have any hope of seeing useful output Test.jar must be in the same folder (directory) that you issue the command from, and Test.jar must have been "exported" by NetBeans as a runnable jar.

Similar Threads

  1. project runs in netbeans but .jar wont work
    By Zeo7 in forum New To Java
    Replies: 3
    Last Post: 12-16-2010, 04:21 PM
  2. Code runs fine but get compile error
    By BillyB in forum New To Java
    Replies: 4
    Last Post: 11-29-2010, 02:18 PM
  3. How to run a project with the command prompt?
    By TexanProgrammer in forum NetBeans
    Replies: 4
    Last Post: 08-05-2009, 10:19 PM
  4. Running eclipse java project on command prompt
    By hnmapara in forum New To Java
    Replies: 1
    Last Post: 07-09-2008, 08:29 AM
  5. accessing command prompt using java (netbeans)...
    By kureikougaiji in forum New To Java
    Replies: 6
    Last Post: 06-27-2008, 03:01 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
  •