This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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
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
Joined: Oct 11, 2002
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.
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.
I run this fir all my apps <path to >\javaw.exe -jar <path to>/app.jar
Joined: Sep 29, 2000
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.
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 ]
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.
Joined: Sep 29, 2000
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.
Joined: Jul 20, 2001
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.
Joined: Apr 24, 2002
amazing how a detail like this can really detract from a language. i wish sun would come out with a better solution.
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.
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 - email@example.com<br /><a href="http://www.matthewwebster.homeunix.net/" target="_blank" rel="nofollow">http://www.matthewwebster.homeunix.net/</a>