Results 1 to 15 of 15
  1. #1
    nhmllr's Avatar
    nhmllr is offline Member
    Join Date
    Aug 2011
    Posts
    51
    Rep Power
    0

    Default No GUI Application, only the console?

    I finished a project, and as very few people will use it, there is no GUI. The only interface is the console. I know from the IDE that the program works fine.

    I've tried a few ways to save the application as a file that I can use, but it doesn't display the console. Is there a way to get it to open to the console window?
    (The program does a few other things, so I know that the program is definitely starting, but the console is never shown)

    Thanks

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

    Default Re: No GUI Application, only the console?

    Windows? Make sure you are starting the program with java.exe and not javaw.exe. See the java man page.

  3. #3
    nhmllr's Avatar
    nhmllr is offline Member
    Join Date
    Aug 2011
    Posts
    51
    Rep Power
    0

    Default Re: No GUI Application, only the console?

    I've been messing around with every option I've seen, but nothing I do addresses the problem.

    Is there a specific way to export it as a java.exe?

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

    Default Re: No GUI Application, only the console?

    It's not a matter of how you export it; it's how you are running whatever it is you export.

    By default (I think) executable jar files open with javaw.exe and you may not want to change this behaviour because it's suitable for other programs. In that case just put a batch file next to the jar which opens it correctly. (Batch files have the extension .bat) The file might just say

    Java Code:
    java -jar MyApp.jar
    This approach will work if you are not putting the application as a jar file. If there are no packages involved the batch file goes next to the corresponding .class file and says

    Java Code:
    java -cp . MainClass
    (If there are libraries that need to be used then the classpath part might have to be changed.)

  5. #5
    nhmllr's Avatar
    nhmllr is offline Member
    Join Date
    Aug 2011
    Posts
    51
    Rep Power
    0

    Default Re: No GUI Application, only the console?

    Batch files seem okay but it seems like there should be a more elegant way to do it without it, especially since my program needs nothing else besides it's source code (and imports like the regular random number generator, but that shouldn't matter)

    Shouldn't there be a way to do it, such that anyone could double click the icon and it just works?
    I've never done this before and I can't figure it out, even when reading tutorials.

    One thing that I keep seeing is a "manifest file"
    What is that and how can I make one using eclipse?

    I don't really know what I'm doing so thanks

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

    Default Re: No GUI Application, only the console?

    There are various options in Eclipse for including a manifest, but to find out what one is and what actually happens when you create a jar file I would recommend Packaging Programs in JAR Files in Oracle's Tutorial.

  7. #7
    nhmllr's Avatar
    nhmllr is offline Member
    Join Date
    Aug 2011
    Posts
    51
    Rep Power
    0

    Default Re: No GUI Application, only the console?

    Okay, I'm really confused.
    1. Where does a manifest file go? Which folder?
    2. I read this:

    java.exe is ever so much easier to understand and use when all the class files are inside a single jar. In that case the member names are identical to the package names. You can hide the console by using javaw.exe (java without) instead of using java.exe.

    I though Java didn't make .exes. And in any case, this sounds like it might be my problem. But how do I toggle between java and javaw?

    I'm really frustrated that I can't find a place that explains these. Thanks

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

    Default Re: No GUI Application, only the console?

    java.exe and javaw.exe are the commands used to run Java.
    SO you're correct, Java does not create exe's.

    The mapping for an executable jar is defined by the OS so, without changing that mapping as and when needed, you can't just toggle between them.
    A batch file is the usual way forward on these things.

  9. #9
    nhmllr's Avatar
    nhmllr is offline Member
    Join Date
    Aug 2011
    Posts
    51
    Rep Power
    0

    Default Re: No GUI Application, only the console?

    I made a batch file

    Here's what was in it:
    java -jar StudyHelper.jar
    java -cp . GtDriver
    It opened the command prompt for a brief second, then closed it right away

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

    Default Re: No GUI Application, only the console?

    Why do you have two things being launched?
    What are you expecting to see?
    Does the program take any input from the user?

  11. #11
    nhmllr's Avatar
    nhmllr is offline Member
    Join Date
    Aug 2011
    Posts
    51
    Rep Power
    0

    Default Re: No GUI Application, only the console?

    Quote Originally Posted by Tolls View Post
    Why do you have two things being launched?
    What are you expecting to see?
    Does the program take any input from the user?
    1. I thought that's how you made it. Woops
    2. My program firsts asks the user to select a text file from their harddrive. The text file is a terms and definitions sheet that one would use to study for a test. The program quizzes the user on the terms found in the text file
    3. Yes, which is why I don't understand why the command prompt closed so quickly.

  12. #12
    Join Date
    Jan 2010
    Posts
    19
    Rep Power
    0

    Default Re: No GUI Application, only the console?

    Quote Originally Posted by nhmllr View Post
    I made a batch file

    Here's what was in it:


    It opened the command prompt for a brief second, then closed it right away
    Open the command prompt (Run cmd.exe) e call your batch file. Copy the output message and share with us.

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

    Default Re: No GUI Application, only the console?

    Right, just done a test jar with a single class and only this in the main method:
    Java Code:
       public static void main(String[] args) {
          Scanner scan = new Scanner(System.in);
          System.out.println("Enter something");
          String s = scan.nextLine();
          System.out.println(s);
       }
    This is jarred into test.jar and exectured with a batch file containing:
    Java Code:
    java -jar test.jar
    This works on Win 7 (and the same sort of thing worked on earlier Wins).

    So, try the same thing on your system. One class, jar into an executable jar. Write a batch. Run it.

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

    Default Re: No GUI Application, only the console?

    Quote Originally Posted by Tolls View Post
    This is jarred into test.jar and exectured with a batch file containing:
    Java Code:
    java -jar test.jar
    This works on Win 7
    That's what I was trying to suggest in #4. Sorry, I might have confused the OP by suggesting *two* commands for the batch file because it wasn't clear to me at that stage whether we were dealing with a jar file or some class files.

  15. #15
    nhmllr's Avatar
    nhmllr is offline Member
    Join Date
    Aug 2011
    Posts
    51
    Rep Power
    0

    Default Re: No GUI Application, only the console?

    Quote Originally Posted by Tolls View Post
    Right, just done a test jar with a single class and only this in the main method:
    Java Code:
       public static void main(String[] args) {
          Scanner scan = new Scanner(System.in);
          System.out.println("Enter something");
          String s = scan.nextLine();
          System.out.println(s);
       }
    This is jarred into test.jar and exectured with a batch file containing:
    Java Code:
    java -jar test.jar
    This works on Win 7 (and the same sort of thing worked on earlier Wins).

    So, try the same thing on your system. One class, jar into an executable jar. Write a batch. Run it.
    It's funny, I tried that and it didn't work, so I have spent the last 10 minutes writing a post on EXACTLY everything I have toggled when I export it in eclipse
    One of suspicious the things I saw that I didn't select was the "Main Class" under "Entry Point"
    I put in my main class, and what'd'ya know, it worked! I clicked the batch file and it ran!
    It makes me feel a little stupid :/

    However it doesn't work unless I click the batch file, so that doesn't put this entire thread to waste

    Thank you everybody!

Similar Threads

  1. Replies: 6
    Last Post: 01-30-2014, 02:56 PM
  2. Help with Console
    By thiagohe in forum Advanced Java
    Replies: 7
    Last Post: 08-01-2011, 02:30 PM
  3. Replies: 2
    Last Post: 03-23-2010, 05:46 AM
  4. console application using jcreator
    By makpandian in forum JCreator
    Replies: 4
    Last Post: 09-07-2009, 05:56 AM
  5. I want to do is clear the console
    By paul in forum Advanced Java
    Replies: 7
    Last Post: 08-03-2007, 07:54 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
  •