Wednesday, July 27, 2011

Starting java applications from the Terminal (Mac)

Starting java applications from the Terminal (Mac)


Sometimes it is useful to start a java application from the terminal in order to see debug information that the application is generating.

Let's assume we have a java application "JPSApp.Application.jar" located in a folder named "jpsapp"

#1 Make sure the application is not running (quit, cancel the app)

#2 Open Terminal (Utilities / Terminal)

#3 Type "cd " (cd [space]) in the terminal

#4 Switch to the finder and locate the application's folder (jpsapp)

#5 Select the application's folder in the finder

#6 In the finder, choose edit/copy or command-c to copy the folder (it's path) to the clipboard

#7 Switch back to the terminal and choose edit/paste or command-v ... you should now have something similar to the following in the terminal window

[mb320:~] dspotts% cd /Users/dspotts/desktop/jpsapp

#8 Press enter ([enter]) ... The above command changes the directory (cd) to the folder "/Users/dspotts/desktop/jpsapp"

You should now see something like:

[mb320:jps/_UAs/jpsapp] dspotts%

#9 confirm you are in the correct directory by typing "pwd[enter]" (print working directory) ... This should display something similar to:

/Users/dspotts/__killboy/prdeliver/__dev/jps/_UAs/jpsapp

#10 start the application by typing "java -jar JPSApp.Application.jar"[enter]

The application's debug / console output will now go to the terminal window you used to start the application!

No comments: