create a link to a terminal command?

zozo
Posted:
in macOS edited January 2014
Hello,



Your local ignorant UNIX/Programmer here.



some engineers here are getting a Java app to finally work on MacOS X.



These guys have UNIX and Windows experience, but never touched a Mac before.



We can launch it via Terminal, and the icon appears in the Dock.. but when I right click the "application" in the terminal and tell it to keep it there, it won't actually launch anything once you quit.



The engineer was looking for a way like in Windows to be able to tell the shortcut to launch a certain file, etc...



Anyway... it was cool to see that without touching a single thing, a great deal of our software worked in about 10 minutes!



Now, off to getting it optimized with OSX specific calls...

Comments

  • Reply 1 of 15
    kickahakickaha Posts: 8,760member
    What command are you using in the Terminal to launch it?



    You *could* save that command to a shell script file, then drag that file to the Dock. Unfortunately, it won't let you place it in the apps section, just the file section.
  • Reply 2 of 15
    zozo Posts: 3,117member
    just a shortcut to get a .jar running...





    the file is in ~/Library/Java/Extensions/opensky.jar



    Uh... btw, my engineers are gone now... how the hell do I get to root level of the HD? How do I get to Library/Java...



    doing CD lets me go to root of my user account...



    crap, why does this always look so easy when the others are zipping by it?
  • Reply 3 of 15
    zozo Posts: 3,117member
    and for some (odd?) reason, it only executes if launched by terminal... I woulda thought that you could just make an alias to that file and double click it... too easy
  • Reply 4 of 15
    kickahakickaha Posts: 8,760member
    Quote:

    Originally posted by ZO

    just a shortcut to get a .jar running...





    the file is in ~/Library/Java/Extensions/opensky.jar



    Uh... btw, my engineers are gone now... how the hell do I get to root level of the HD? How do I get to Library/Java...




    In Terminal? 'cd /'



    In Finder? Click on the hard drive icon in the sidebar, or hit shift-cmd-c and select it there.



    Quote:

    doing CD lets me go to root of my user account...



    crap, why does this always look so easy when the others are zipping by it?




    Because they're driving.



    And double-clicking the file in the Finder doesn't work because the Finder doesn't know about all the Terminal level apps, so it doesn't know what to do with the file you double-clicked.
  • Reply 5 of 15
    zozo Posts: 3,117member
    last 2 stupid questions for the night:



    - How do you start the Jar file? It says -bash: opensky.jar: command not found



    - If and when this works again, how do I save it as a script? which parts do I save?
  • Reply 6 of 15
    kickahakickaha Posts: 8,760member
    open a new document in TextEdit. Format menu -> Make Plain Text.



    Type into it:



    #!/bin/sh



    java /Library/Java/Extensions/opensky.jar





    Save this file where ever you want. Name it 'Opensky.command' When TextEdit gripes about the extension, override with 'don't append'.



    In the Terminal, go to the folder where the above file is stored, and type 'chmod ugo+x Opensky.command' without the quotes. Hit return.



    You should now be able to double-click *that* and run the .jar file.



    You can also drop it into the (document section of the) Dock.
  • Reply 7 of 15
    zozo Posts: 3,117member
    awesome... but it dont work.



    I dunno what my engineers did, but it worked for them... it doesnt here.



    I double click the newly created Opensky.command file and it tells me (in the Terminal)



    Exception in thread "main" java.lang.NoClassDefFoundError: /Library/Java/Extensions/opensky/jar

    logout

    [Process completed]



    *sigh*



    Anywya, dont worry... I'll just wait till tomorrow. Unless you want to try something else...



    dammit man! it JUST WORKED when he gave a the path for that jar!! I've restarted the computer since... but I dont see why that would make a difference.



    Thnaks for your time Kicka
  • Reply 8 of 15
    gargoylegargoyle Posts: 660member
    the Jar file should just run!



    Edit:

    Found it.



    Right click the jar file and choose "open with". Then goto /System/Library/CoreServices/Jar Launcher



    If you do this in the info panel, you should be able to set it as default.
  • Reply 9 of 15
    beamsobeamso Posts: 11member
    I'm going to go in a different tangent to everyone else in this thread (and this supposes that the Java app has a GUI to it).



    If you've got the Developer Tools installed, there's a program called Jar Bundler in /Developer/Applications/Java Tools/.



    You can use this program to create a double-clickable Java .app (like other programs on Mac OS X). All the .jars used in the Java application can be stored in a subdirectory of the <program-name>.app folder.



    There's also some Apple-proprietary classes that can be extended so that the application menu can be used successfully (quitting using cmd-q, getting preferences, interacting with the dock).



    In reference to other instructions given:



    Kickaha's instruction is slightly wrong. If the program is just a single .jar (with no dependencies apart from the standard Sun Java classes, and the manifest properly created to point to the class with the public static void main() method) then java -jar /Library/Java/Extensions/opensky.jar is the most appropriate command. If it has dependencies on other jars, then java -classpath <list of .jars separated by ':'> <name of class in opensky.jar with the public static void main() method) is the way to go.



    EDIT:



    I forgot to mention a reference for Java on Mac OS X:

    Apple Reference Library - Java

    That link will have instructions on how to use Jar Bundler, plus the Apple proprietary classes and more information.
  • Reply 10 of 15
    zozo Posts: 3,117member
    cool, I'll try this out later. Gotta go home.



    Indeed, there are many other JAR files in the Extensions folder.



    sorry... didnt know it was relevant..



    And yes, I have dev tools installed.

    ZO
  • Reply 11 of 15
    Quote:

    Originally posted by Kickaha

    Type into it:



    #!/bin/sh



    java /Library/Java/Extensions/opensky.jar





    Not quite...



    java -jar ~/Library/Java/Extensions/opensky.jar



    Hope that helps. m.
  • Reply 12 of 15
    Quote:

    Originally posted by ZO

    Exception in thread "main" java.lang.NoClassDefFoundError: /Library/Java/Extensions/opensky/jar



    You said before that it was in your home folder's Library folder. hence, you need the ~ before /Library/... for it to work. m.
  • Reply 13 of 15
    kickahakickaha Posts: 8,760member
    Listen to him, I haven't used Java from the command line in a couple of years, and never on my Mac.
  • Reply 14 of 15
    Quote:

    Originally posted by Kickaha

    Listen to him, I haven't used Java from the command line in a couple of years, and never on my Mac.



    From what Apple does with building a GUI implemenation with Java, it is so much more elegant than windows counterparts.



    But, then again, what isn't better on the Mac.

    -walloo.
  • Reply 15 of 15
    zozo Posts: 3,117member
    awesome... I tried the "Jar Bundler" app and aside from a lockup the first time it ran, I just told it where the main Jar file was, and the other Jar files associated with it, and whammo, it spit out a nice little .App which ran like a treat!!!



    Now then... there is a ton of OS specific things that will have to be modified in the source to get it to work properly on OSX... but hopefully that will come soon.



    Thanks for all your help



    PS Anyone wanna beta test? ;-)



    just kidding... its a Internet via Satellite app, so I doubt anyone will have any interest in it
Sign In or Register to comment.