Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > using command line program

using command line program
Thread Tools
Fresh-Faced Recruit
Join Date: Jun 2003
Location: Charlottesville, VA
Status: Offline
Reply With Quote
Aug 30, 2003, 08:17 PM
 
so I wrote a fun little desktop changing program that I've always wanted to do. I wrote it in java as a command line app b/c that's all I have ever known how to do (from school). I've never written a complete program start to finish including gui and install and such, but I'd like to do that with this.

So now I have a couple questions. First, I'd like to create a double-clickable jar file that would launch it the way it is (command line). Is that possible? If so how, I have a class with a main, but when I create a jar out of it, it doesn't automatically launch into a terminal window or anything. I figure that the launcher wants some gui code, but I'm trying to aviod that for a moment.

Next, I will eventually use the java code with cocoa gui (don't really know how that works yet). Is the best way to do that to create a jar file and use that with gui, or just keep the java code seperate?

I'm currently more concerned with getting a double-clickable command line jar if that's possible b/c I haven't really delved into the gui yet, but future advise is always welcomed.

thanks,
matt
     
Fresh-Faced Recruit
Join Date: Jun 2003
Location: Charlottesville, VA
Status: Offline
Reply With Quote
Aug 30, 2003, 08:35 PM
 
I just took another look at it, and recreated the jar and launched it again. And it turns out that it sends stuff to console and then spits out an error. So I guess I'm wondering if there is a way to tell the launcher to launch this in a terminal window?
     
Forum Regular
Join Date: Jul 2002
Location: Australia
Status: Offline
Reply With Quote
Aug 30, 2003, 10:56 PM
 
I've got no idea how to get a terminal window to open automatically from a .jar. I doubt it's even possible. The best aproach is probably to write a shell script that invokes the jar - give it a .command extension and Terminal will run automatically when you open it in the Finder.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Aug 31, 2003, 05:03 AM
 
You can write double-clickable Cocoa applications using Java, if you want to... Just create a new "Cocoa-Java Project" to see what's going on. However, this won't work for CLI tools as their stdout will be redirected to /dev/console and other such jazz.

If you have a swing GUI, the correct way to create double-clickable apps is using MRJAppBundler or whatever it's called.
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Sep 1, 2003, 08:01 AM
 
In order to make a double-clickable jar work, you have to custom-modify the manifest in the jar to tell it which class is the "main" class that should be run.

The manifest should look something like this:

Code:
Manifest-Version: 1.0 Main-Class: net.theresistance.simpleClass
Of course, you'd replace the Main-Class value with your class.

That will make it run in CLI-mode. It will not open a terminal or anything, so you can't do command-line arguments or read input or print output this way.

If you want features like that, you'll have to learn AWT or Swing.
(Last edited by Arkham_c; Sep 1, 2003 at 08:16 AM. )
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:21 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2