Results 1 to 15 of 15
- 01-18-2012, 02:55 AM #1
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
- 01-18-2012, 04:20 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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.
- 01-18-2012, 05:28 AM #3
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?
- 01-18-2012, 05:40 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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
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 saysJava Code:java -jar MyApp.jar
(If there are libraries that need to be used then the classpath part might have to be changed.)Java Code:java -cp . MainClass
- 01-19-2012, 04:18 AM #5
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
- 01-19-2012, 04:23 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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.
- 01-20-2012, 12:14 PM #7
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
- 01-20-2012, 12:38 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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.
- 01-20-2012, 12:55 PM #9
Re: No GUI Application, only the console?
I made a batch file
Here's what was in it:
It opened the command prompt for a brief second, then closed it right awayjava -jar StudyHelper.jar
java -cp . GtDriver
- 01-20-2012, 01:46 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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?
- 01-20-2012, 01:51 PM #11
Re: No GUI Application, only the console?
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.
- 01-20-2012, 02:15 PM #12
Member
- Join Date
- Jan 2010
- Posts
- 19
- Rep Power
- 0
- 01-20-2012, 02:20 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: No GUI Application, only the console?
Right, just done a test jar with a single class and only this in the main method:
This is jarred into test.jar and exectured with a batch file containing: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 works on Win 7 (and the same sort of thing worked on earlier Wins).Java Code:java -jar test.jar
So, try the same thing on your system. One class, jar into an executable jar. Write a batch. Run it.
- 01-21-2012, 12:06 AM #14
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Re: No GUI Application, only the console?
- 01-21-2012, 07:31 PM #15
Re: No GUI Application, only the console?
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
-
Application runs in Eclipse console. How to make it a stand alone app?
By tmboredi in forum New To JavaReplies: 4Last Post: 01-12-2012, 05:25 PM -
Help with Console
By thiagohe in forum Advanced JavaReplies: 7Last Post: 08-01-2011, 01:30 PM -
Calling a .Net webservice(Password Protected) from java console application
By charan reddy in forum Advanced JavaReplies: 2Last Post: 03-23-2010, 04:46 AM -
console application using jcreator
By makpandian in forum JCreatorReplies: 4Last Post: 09-07-2009, 04:56 AM -
I want to do is clear the console
By paul in forum Advanced JavaReplies: 7Last Post: 08-03-2007, 06:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks