Associating files to java application
Hey!
I want to know if it's possible to associate files of certain types with my java app.
for example, would it be possible for a Java-based text editor to open every time a .txt file is double-clicked, or run in some other manner?
what i mean is that on clicking the .txt file, my application should open, and the file's uri should be passed as an argument to it.
any help would be appreciated. even platform-specific codes like shell-scripts/batch-scripts would do.
Re: Associating files to java application
Yes you can on Windows and perhaps on linux.
This isn't related to java programming. It's an OS setup problem.
In windows you can specify the commandline you want executed when double click on a file with a given extension. This is controlled by entries in the Registry.
With XP you can see/change the entries by (This is for jar files, change to extension to your choice)
Open Windows Explorer
Click on Tools menu
Click on Folder Options
Select File Types tab
Scroll down in the "Registered file types:" list until you see an entry for JAR.
Select the JAR entry.
Click the Advanced button
In the Edit File Type window scroll down the list of Actions until you see the one in bold.
Select the bold one
Click the Edit button
Select, Copy and paste here what is in the "Application used to perform action:" window.
Be careful not to change anything and Cancel your way out of the open windows.
Re: Associating files to java application
Sorry, but probably my question is not clear enough.
I can always right click on the file in windows, and select OPEN WITH -> MyApp.jar but how do i pass the location and name of the file to the jar file?
Re: Associating files to java application
In the command line in the Registry you use a place holder like: %1 or %*
If you do the steps that I posted in #2 you will see what a command line looks like.
Here is a sample command line from my registry:
java.exe -cp D:\JavaDevelopment\runtime\CheckClassRefs.jar;. CheckClassRefs "%1"
Re: Associating files to java application
thanks! i guess i get it!
some more help with a batch file, though:
could you please write a batch script for me that does the following work:
1. takes a file as an argument
2. stores the file's directory in a variable
eg. input:
bfile "C:\hello\hi\tada.txt"
output(should be saved in a variable):
C:\hello\hi
Re: Associating files to java application
Sorry, this is a java programming forum. Try a forum for the OS you are working on.
Re: Associating files to java application
is it my fault that java runs like a freaking interpreted language?
should've opted for c/c++, and my life would have been a LOT easier. im not asking all these questions for teh lulz. my question here is bloody related to java. i dont see how it isn't.
Re: Associating files to java application
look. it's 2:00 am in my country right now. kindly help me if you can. im bloody stuck here, and its getting frustrating.
Re: Associating files to java application
Quote:
write a batch script
Batch files are strictly an OS thing.
Java is definitely interpreted. A benefit is that the same code can run on many OSs without any changes. Copy the jar file and the program runs.
Re: Associating files to java application
tell me how to write the batch fle to launch my java application! i am WILLING to sacrifice portability!
running on ONE platform is better than not running at all!
Re: Associating files to java application
You will not need a batch file to execute a jar file. The JDK and JRE installations make the Registry entries needed to execute a jar file. Put your class files in a jar file with a correct manifest and then double click the jar file to execute it.
Re: Associating files to java application
divs1210, you are posting your way out of receiving any help from anyone. Contributors spend their free, unpaid time to help give advice such as Norm has provided. I recommend you try and show a little respect and refrain from posting obscenities directed at said contributors. I have deleted your discourteous post, and am locking this thread