aspose file tools*
The moose likes Java in General and the fly likes What's up with this DOS window? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What Watch "What New topic
Author

What's up with this DOS window?

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I wrote a small Tic-Tac-Toe game as a standalone Java application. When I run it, a dos window comes open and stays open under the game. When I exit, the window closes. Is this the Java Console for standalone apps? What is it? How do I use/control it, and what is its purpose?
------------------
���
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20271
    ∞

All java programs have a console to send stuff too (like progress messages or errors). Even applets, although the console is usually hidden.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Fair enough. Are there methods to control this window? For example, as you mentioned, it is usually hidden for applets. Can I hide it for a standalone application?
If I go out and buy an off-the-shelf Java application, will I still have to look at this DOS window while I run it? It just seemed sort of unfinished and unprofessional looking to have that on screen.
------------------
���
Pawel Veselov
Ranch Hand

Joined: Jan 14, 1999
Posts: 165
No, you can't.
The problem is that java.exe opens this window (acutually, because it is not a GUI application, but a console one). By closing this window you will destroy the JVM itself, since it's his controlling window.
The source of this problem may lay in Unix OS, where any application can be started from a console or from another application, who will take care for any ouput produced by child application.
If you expirienced with windows programming you can try calling java.exe from an external program, like wrapper to redirect stdout/stderr. I am not sure it is possible in windows, though.


------------------
With best of best regards, Pawel S. Veselov ( aka Black Angel )

With best of best regards, Pawel S. Veselov ( aka Black Angel )
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I don't know the exact details (I'm usually the Java specialist, and someone else wrestles with Microsoft), but it is possible for a Windows program to hide and/or minimize a DOS window, or operate as a GUI application and not bother with one. Either find a Windows app that's written in Java and work out how it does it, find a Windows/Java expert who's done it, or spend a lot of time and experimentation with books and web sites.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Ok, I went to Sun's site and downloaded the Swing demos for 1.1.1. The demos are all .EXE's!! How is this accomplished? I just wanted to look at their source to see how they got around the goofy DOS window.
------------------
���
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I was out tooling around on java.sun.com and I found this reply to a bulletin board posting:
...This solution works for the older JDK's (our application runs on JDK 1.1.8, though it should work with 1.02 or 1.2.x as well), and Windows 95/98/NT.
To install our Java application, we have the users copy a directory from a CD to their local drives. (You can also zip everything up into one zip file for distribution.) The directory has a bin and a lib subdirectory containing the jre. Also in the directory is a jar file containing all of the application's class files, and a batch file.
The user runs the program by double-clicking the batch file from Explorer. You can also make a shortcut of the batch file, and put it on the desktop or in the Start menu. Either way, the Java application runs WITHOUT an unneeded DOS frame! Here's how the batch file is set up to do its magic:
Contents of the 2-line run.bat:
@echo off
@start bin\jrew -classpath lib\classes.zip;.\myJarFile.jar MyMainClass
When you run the batch file, it briefly launches a DOS frame, which immediately completes its business and closes itself. The Java application appears shortly afterward in its own java.awt.Frame.
Notes: To get the DOS frame to disappear automatically in Windows 95/98, you MUST do the @echo off part. The DOS frame won't go
away if it's displaying any text. Windows NT doesn't have this problem.
The "start" command spawns the java application off in its own DOS interpreter. This allows the batch file to "keep on going", and finish up without waiting for our java application to terminate. Once the batch file is done, the DOS window is able to close on its own.
For those who don't know, jre.exe works essentially the same as java.exe for the purposes of running your Java program. jrew.exe works just like java.exe, too, but it doesn't spawn a new DOS window.
Since the batch file references the jre.exe and classes.zip that we ship along with the app, there is never any chance of conflicts with any JDK version the user might have already installed. Also, we don't make the user manually install the JDK or muck about with path settings. And, this batch file will work no matter where the user decides to install our application's directory. This is the perfect solution for those of us who have to distribute our programs to computer illiterates!
Hope this helps people!
-Kip Fiebig www.kipley.com
kip.fiebig@tivoli.com

Credit where credit is due: Thanks for the info, Kip! It was exactly what I have been looking for.
------------------
���
Matt Midcap
Sheriff

Joined: Jan 07, 1999
Posts: 440
Bodie,
You exactly right about the "jrew.exe"! Good job finding this info.
Also, if you want to make a windows short-cut for you app and put it on your desktop, you can also use "javaw.exe". Try something like:
<pre>%windir%\System32\javaw.exe -cp .;c:\someApplication\aJarFileNeededToRun.jar nameOfClassFileWhereMainIsLocated</pre>
I also spent a lot of time on this bugger so please let me know if you have any more questions about it.
Best Regards,
Matt


Best Regards,<br />Matt Midcap
 
wood burning stoves
 
subject: What's up with this DOS window?
 
Similar Threads
javaw
Java to Exe using Microsoft SDK
help i cant start tomcat
DOS command window
Problem with James and Phoenix for Java Mail