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
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.
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?
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
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
Code:
java -cp . MainClass
(If there are libraries that need to be used then the classpath part might have to be changed.)
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
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.
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
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.
Re: No GUI Application, only the console?
I made a batch file
Here's what was in it:
Quote:
java -jar StudyHelper.jar
java -cp . GtDriver
It opened the command prompt for a brief second, then closed it right away
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?
Re: No GUI Application, only the console?
Quote:
Originally Posted by
Tolls
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.
Re: No GUI Application, only the console?
Quote:
Originally Posted by
nhmllr
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.
Re: No GUI Application, only the console?
Right, just done a test jar with a single class and only this in the main method:
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:
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.
Re: No GUI Application, only the console?
Quote:
Originally Posted by
Tolls
This is jarred into test.jar and exectured with a batch file containing:
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.
Re: No GUI Application, only the console?
Quote:
Originally Posted by
Tolls
Right, just done a test jar with a single class and only this in the main method:
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:
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!