aspose file tools*
The moose likes Beginning Java and the fly likes Annoying DOS window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Annoying DOS window" Watch "Annoying DOS window" New topic
Author

Annoying DOS window

Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
I want to launch a Java app without having a DOS window up. Is this possible?
I thought it might be possible to make a non-visible window with standard windows programming, but I've forgotten how to do that (Java's just so much nicer to program with). Anybody know?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Try running your program using javaw instead of java. For example, if your class file is Test.class, type javaw Test instead of java Test.
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
What difference does that make?
You still have to launch it from a batch file or something, and the DOS window remains (or have I missed the point somewhere?)
What is Javaw anyway? I couldn't see it in the docs.
ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
Hey that's nifty!! sorta...you still hafta kick off the javaw from a DOS window but you can close the DOS window using the "X" in the upper right hand corner and you Java App should stay open..mine did.
Or you could copy javaw.exe into the same directory as your class file, the select start->run and then type the path to your class file along with javaw.exe like this:
javaw.exe c:\stuffIwrote\helloworld
it worked for me.

[This message has been edited by ryan headley (edited November 10, 2000).]


Ryan Headley<br /><a href="http://www.sudovi.com" target="_blank" rel="nofollow">http://www.sudovi.com</a>
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Grant,
Yup, you still have to kick your app off from a batch file. On Windows 95/98 you can set a property in your batch file to close the window when the progam finishes. This is found by right-clicking on the shortcut for the batch file and choosing properties.
OR
As Ryan said, you could call your program from Start->Run and the window will go away on its own.
Javaw is another way to invoke the JVM (I think it's supposed to be Java for Windows or something like that.) All I know about it for sure is that it works pretty well.
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
Yeah, that works.
But it still doesn't solve my problem: I want it so that you (or, more specifically, someone else) can just click on an icon and get my application, no DOS window, no messing.
I thought perhaps I could use
Runtime.getRuntime().exec( "exit" );
in combination with javaw, but that doesn't work as the DOS window is still busy running the app (or, at least, you can't write in it). Where is the documentation on javaw? perhaps there are some arguments you can pass to it to achieve this.
Thanks, all the same.
ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
Here is what you have to do to get it to run from an ICON.
copy javaw.exe to the place where your class can be found. then on the desktop create a shortcut that points to javaw.exe.
(i.e. if my class was in a directory call stuff, create a shortcut that points to c:\stuff\javaw.exe. Finish creating the icon. Once its on your desktop, right click the icon, go to properties, shortcut and add your class file name to the end of the shortcut path. So when you are done you will have in the path for the shortcut:
c:\stuff\javaw.exe HelloWorld.
Then click ok.
that should do it!
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
Ryan, you are my hero.
I knew it would be possible, it just had to be... No more annoying DOS windows for me!
If anyone else wants to do this, an icon is just a bitmap (not sure if the colour depth matters, I use 24-bit - and I think they are 32x32 pixels) and give it a .ico extension - paint can be used.
Create a shortcut using javaw like Ryan said, and select your icon using the 'change icon' button under Properties, Shortcut.
One last thing... Anyone know about the legalities of distributing javaw with a commercial app?
Anyway, thanks again.
ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
awww shux....'tweren't nuthin'...
Jimmy King
Greenhorn

Joined: Nov 15, 2000
Posts: 1
Open your shortcut properties and select "run minimized". This only works on apps, not appletviewer...
I'm severly novice so forgive if this is not what you wanted...
anrup kris
Greenhorn

Joined: Oct 22, 2000
Posts: 17
I wanted to try out this javaw command.I tried running one of my classes with javaw,but nothing happens.
The javaw .exe file is present in my jdk1.2.2/bin directory.I dont get any error message but nothing executes
can anyone help?
thanx
kris
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
You just use javaw instead of java. Are you running it in the directory where the class file is? javaw doesn't seem to give any error messages or anything, so it's hard to tell what you're doing wrong, but it must be working or you'd get 'command not recognised' or whatever.
Are you running Windows? If not, it could be that javaw is a Windows-only thing.
Noah Carroll
Ranch Hand

Joined: Sep 20, 2000
Posts: 96
An even easier way and seemingly cleaner way to solve this problem is to put all of the necessary files into a jar file, and the add the line
Main-Class: MainClassName
Then you can simply double click the jar file and it is self-executable. It is easy to do, and very convienient
------------------
I hope its helps, feel free to email me noahcarroll@juno.com
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi. I am trying to make a shortcut using the above suggestion, copy javaw.exe to the same path as my class file. I successfully created the shortcut to the javaw.exe file, but when I try to add my class name, I get an error saying that the specified name in the target box is invalid?? Here is what I have:
"I:\VSK JavaPrograms\com\storekraft\ord\javaw.exe CVOrderEntry" (I am using W2KPro)
I also have another question. If I have users accessing this file from the server, where is the application actually running? Is it running on the server, or running on the client? Do I have do install JRE on each client machine still?
Thanks for any help.
[ December 19, 2002: Message edited by: Jennifer Sohl ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I get an error saying that the specified name in the target box is invalid??
In my experience, trying to create such a shortcut that would work the same on all installations of Windows can be difficult. Perhaps creating an executable JAR file would be preferred. (This would also run on any system with a Java 2 JRE properly installed.)


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
If I have users accessing this file from the server, where is the application actually running? Is it running on the server, or running on the client? Do I have do install JRE on each client machine still?
That would probably depend on your network.
Manikantan Narender
Greenhorn

Joined: Jan 04, 2003
Posts: 1
Folks No need of copying javaw to the directory where the class files are. Simply jar your files with a manifest file
The manifest file should contain
few headers
Main-Class: <Your main class>
Class-Path: <use relative paths-relative to the jar file I mean>
The default executor for jar files is javaw. if you have changed it to winzip or gzip or anything restore it back.
For more information on manifests, check out the java.sun.com site


Manikantan
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
This problem seems to be solved, but here's a nifty bit of info many of you might be interested in. Try this:
(start my_batch_file.bat)
javaw MainClass
cls
(end my_batch_file.bat)
The 'cls' clears the screen. Since there isn't any output for the user to read, the window just closes when it's done.
Rico Anderson
Greenhorn

Joined: Dec 29, 2003
Posts: 2
or, and this has been tested on Win-XP, do NOT copy javaw.exe:
1) create a working .bat file to start the app, e.g.:
C:\jdk\bin\javaw.exe -classpath "..." myPack.HelloWorld
make sure, the .bat file works from any directory, i.e. that the path to "myPack.HelloWorld" has been included in the classpath.
2) create a shortcut and copy the whole string created under (1) into the shortcut's target field
viola, works just as well, without the need to copy javaw.exe
Jonathan Griffin
Greenhorn

Joined: Jan 12, 2004
Posts: 2
There are several options to getting your app to run without the dreaded DOS prompt. Some options have already been mentioned above, such as using a jar file or a batch file. Another viable option would be to wrap your application with an EXE. Here's a commercial one: NativeJ. There are a few free ones, but I don't have the links with me. I will try to get them later.
However, for a quick and simple way to run your app w/o a DOS prompt, simply setup a shortcut link on your desktop or whereever else you need it. You can usually find javaw.exe in the c:\windows\system32 directory, as well as the bin of your JRE or SDK.
STEPS FOR SETTING UP SHORTCUT:
  • Right-click on desktop or in folder and select New/Shortcut.
  • In the "Type the location of the item" textbox, type in the target path (see examples below).
  • Give the shortcut a name and your done.


  • Target Path Examples:
    c:\j2sdk1.4.2_03\bin\javaw.exe -cp c:\myapp MyApp
    c:\windows\system32\javaw.exe -cp c:\myapp MyApp
    * Notice we pass the classpath to our application to javaw.exe.
    You now have a simple and quick shortcut that will fireup your application w/o a DOS prompt!
    Enjoy!
    Jonathan Griffin
    Greenhorn

    Joined: Jan 12, 2004
    Posts: 2
    I mentioned a free Java to EXE program in my previous posting. Well I found the link.
    ExecJava 1.0
    Johnothan Doe
    Greenhorn

    Joined: Feb 27, 2004
    Posts: 3
    All you need to do is in your bat file put the "start" before you reference the javaw.exe. It does not need to be in the same directory. This allows the bat file to continue after issuing the javaw command without having to wait until the application exits.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Annoying DOS window