 |
 |
Java command line app...
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
so i was thinking of creating a command line app in java and was wondering if it's possible to compile it so that it can be executed without having to do:
[PHP]% java myApp[/PHP]
also, i've only created apps for my comsci classes so i've never really had to package an app for public consumption before. can someone explain to me .jar files so that i don't have a million .class files all over the place. i want one file that people can install and then execute...
thanks for any help
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Dec 2001
Location: Zurich (Switzerland)
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
cool, thanks for the info. is it safe to say that a double-clickable app will also be one that can be executed from the command line by just typing it's name (given it's in the path...)?
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jul 2002
Location: Australia
Status:
Offline
|
|
You won't be able to run the .app bundle the command line with just it's name, since bundles are directories. You'd need to use 'open AppName.app', and I'm pretty sure stdout doens't go to the console this command was run from.
As far as I know, you'd need to write a small shell script that runs the java .class or .jar.. or you could look into the GNU Compiler for Java (which I've only ever used on Redhat Linux, never attempted to get it working on OS X).
(Last edited by asmodeus; Jun 12, 2003 at 09:31 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
Originally posted by asmodeus:
You won't be able to run the .app bundle the command line with just it's name, since bundles are directories. You'd need to use 'open AppName.app', and I'm pretty sure stdout doens't go to the console this command was run from.
...yeah, you'd have to use open.
As far as I know, you'd need to write a small shell script that runs the java .class or .jar.. or you could look into the GNU Compiler for Java (which I've only ever used on Redhat Linux, never attempted to get it working on OS X).
this looks interesting, do you know if it's bundled with the dev tools version of gcc (i would check but am at work on a pc). if not, would it be as simple as just downloading gcj and executing it, or does it need to be configured along with gcc...(i'm still new with this stuff...)
or, if i were to go the shell script route, would there be a smart way to package it in a way that would be transparent to the user? so that they would only have to worry about one file? i know this is the concept of packages, but as you said, the shell treats them as directories.
...perhaps i should just write this in c or learn obj-c.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by ameat:
or, if i were to go the shell script route, would there be a smart way to package it in a way that would be transparent to the user? so that they would only have to worry about one file? i know this is the concept of packages, but as you said, the shell treats them as directories.
You can do this, but unless it's an installer, it's not recommended.
The solution is basically to uuencode your binary (.class or h.jar file) inside the shellscript, then you have the script "decode" itself on the filesystem before running. Crazy, I know, but it will work.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
Originally posted by Arkham_c:
You can do this, but unless it's an installer, it's not recommended.
The solution is basically to uuencode your binary (.class or h.jar file) inside the shellscript, then you have the script "decode" itself on the filesystem before running. Crazy, I know, but it will work.
poop. any resources that might divulge how to go about doing this? thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 1999
Location: Ottawa, ON, Canada
Status:
Offline
|
|
Originally posted by ameat:
poop. any resources that might divulge how to go about doing this? thanks.
Here:
uuencode your binary (.class file). You will get a text file that contains
begin
685dcbr6a7fdsgsdahfjkarewf67asrtf67rea
f6das78f9fdsa76fhsdaf87ewf6sda78fhwe87
...
end
At the top of that text file put
grep -v grep > /tmp/yourapp.installtmp;uudecode yourapp.install.tmp > /tmp/yourfinalcommandname;chmod u+x /tmp/yourcommandname;/tmp/yourcommandname
Put that all on one line. So all the user has to do is run the name of that text file you created each time (s)he wants to run the program.
Another option is to distribute two files - the .class (or .jar) file and another text file with the command "java yourfile.class" in it. The user just types that text file (make sure it is given execute permission).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by ameat:
poop. any resources that might divulge how to go about doing this? thanks.
Made a sample for you. It runs a java app:
http://david.theresistance.net/files/HelloThere.tgz
Inside the archive is a script "HelloThere", as well as a folder containing the pieces I used to make it.
(Last edited by Arkham_c; Jun 12, 2003 at 07:00 PM.
)
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
very cool. thanks everyone for your help...interesting little learning experience...
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
...well, nevermind. the app that i had been wanting to write was just released ( Contacts). i should just do it for the exercise...oh well...thanks all for you help. it'll probably be usefull in future projects anyway.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|