aspose file tools*
The moose likes Java in General and the fly likes Launching a Java app from the desktop. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Launching a Java app from the desktop." Watch "Launching a Java app from the desktop." New topic
Author

Launching a Java app from the desktop.

Adam Till
Ranch Hand

Joined: Oct 11, 2002
Posts: 41
Howdy
I am trying to find out how to launch my Java app from an icon on the desktop.
So far I have the icon that links to a .bat file. However the command line box still stays open even though I put the exit command in the .bat file:-
java myapp
exit
Does anyone know how to do this and is this the best way of launching java files?
Adam


Adam Till<br />SCJP SCJD SCWCD
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
hmmm . . my DOS boxes all close when I exit my Java app and we do not use the exit command in the .bat file. We also just hook the icon to the .bat file.
Are you using System.exit(0); when you are leaving your app?
What version of Windows are you using?


"JavaRanch, where the deer and the Certified play" - David O'Meara
Adam Till
Ranch Hand

Joined: Oct 11, 2002
Posts: 41
Windows XP. I dont have the System.exit bit in yet just opening a simple form, what I was trying to do was have the DOS box close as soon as the app begins to run.
Is this possible or does it always stay open?
Thanks for your reply by the way.
Jon Dornback
Ranch Hand

Joined: Apr 24, 2002
Posts: 137
try using javaw instead of java in the shortcut.
javaw myapp
it will launch the app without launching the console window (i assume your program is a gui).
you might have to add the classpath as an option to the command.


use the [CODE] tags - it makes it much easier for people to help you.
Pascal Got
Greenhorn

Joined: Mar 05, 2002
Posts: 23
I run this fir all my apps
<path to >\javaw.exe -jar <path to>/app.jar
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
javaw.exe no longer leaves out the DOS box. There were just TOO many issues with not having a place to write error messages to. You might remember this as you try to do without it.
All of our apps leave the DOS window open but minimized (you can set that in your icon).
What javaw does now is allow the user to close the window after it comes up.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Lose the .BAT file, just create an executable JAR file and double click on it.


GenRocket - Experts at Building Test Data
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
But then, of course, you can not use a different classpath than the user normally does.
And you can not set a different Path on the fly.
And you can not include parameters when you fire up your app. For instance - it sure does make it alot easier if you can take in the name of your properties file as a parameter. The file can then stay editable outside the jar file etc.
[ October 11, 2002: Message edited by: Cindy Glass ]
John Smith
Ranch Hand

Joined: Jul 20, 2001
Posts: 84
I wouldn't use a batch file or an executable jar. I have been using something similar to this for some time now. I haven't had any problems with path/classpath issues, incorrect JRE's being used (assuming you bundle your Java app with a JRE, which you should), etc., since I started using it.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Well for actual distribution we bundle everything up using InstallSheild. We just put an install executable on a web page. The user downloads it, double clicks that, and everything self installs for you, and puts an icon on the desktop for you.
All the end user does is click an icon.
I don't see the advantage of this product. The only thing that it saves it writing 3 lines of .bat file code. And you STILL have to tell that information to this Launcher - so no savings at all.
John Smith
Ranch Hand

Joined: Jul 20, 2001
Posts: 84

All of our apps leave the DOS window open but minimized (you can set that in your icon).

Don't your users find this annoying? I know I would. Using a C++ launcher program to get rid of DOS windows is one advantage over batch files. Also, if you don't mind dabbling in C++, you can modify the launcher (or create your own - it's very few lines of code) to display a splash screen, or do other OS/machine specific things. The nice thing about the splash screen is that it displays immediately since it doesn't have to wait for Swing/AWT to load.
Jon Dornback
Ranch Hand

Joined: Apr 24, 2002
Posts: 137
amazing how a detail like this can really detract from a language. i wish sun would come out with a better solution.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Coming up with a better solution would take away the write once, run anywhere philosophy that Sun has tried so hard to adhere to. If they were to provide you ways to distribute your application beyond what they already have, they would have to provide those methods for each platform and supply them seperatly.
That's why InstallShield exists, Batch files, Shell Scripts, etc. So you have options, but Sun doesn't have to worry about them.
Matthew Webster
Ranch Hand

Joined: May 10, 2001
Posts: 51
I launch my own Java apps from the desktop all the time, one Iv'e got is called JScratchPad...
In my runScratch.bat the line to launch the java app (once setting of paths etc is done) is:
start "JScratchPad" "%JAVA_HOME%\bin\javaw.exe" -ms16m -mx20m -cp "%CLASS_PATH%" %APP_CLASS% %*
The start is the Windows/DOS command to run without a Dos window and javaw is the Java window-less startup command. I use both because I and my colleagues have had problems with just using one.
Have fun...
Matt.


Matthew Webster - eudoxus@freeuk.com<br /><a href="http://www.matthewwebster.homeunix.net/" target="_blank" rel="nofollow">http://www.matthewwebster.homeunix.net/</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Launching a Java app from the desktop.