Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop file onto .jar and pass filename to main()

I'd like to drop a file onto my jar and have the filename passed on to my main method as argument. I'm on OSX. How can I do that?

like image 802
tzippy Avatar asked Jan 30 '11 02:01

tzippy


2 Answers

If the app. is deployed using Java Web Start, a file association can be declared. Double click any file of that type and the path of the file is supplied to the main(String[]).

BTW - here is a demo. of the JNLP file API. Note well the 2nd bug report, which would mean a minimum version of 1.6.0_10+ in order not to delete a file dropped on the application's icon.

like image 123
Andrew Thompson Avatar answered Oct 20 '22 19:10

Andrew Thompson


To do this on OSX you might have to create an application bundle from your .jar. This process is documented pretty well at the Apple Developer Center (scroll down to "Mac OS X Application Bundles"). You can build a Java app which blends really well into the OSX desktop if you follow what they present there, and it's pretty easy.

like image 24
Waldheinz Avatar answered Oct 20 '22 21:10

Waldheinz