简体   繁体   中英

File association using my executable jar file

I have assigned an extension name for my files called *.XSCA. I would like to read the content of this file when the user click on it using my executable jar file to open it. How can I do that?

assuming you work under windows:

  • create a batch-file (*.bat) that calls your jar (it should just be something like "java -jar yourJar.jar")
  • click right on a file of your type, go to "Properties" and change the program that opens your file to that batch-file
  • let the batch-file pass the file-location as an argument to your jar

You can write a batch-file with any text-editor. Use google to find out how. It will just be a wrapper for your jar that you can associate in windows with your file-extension-type.

EDIT:

OK, step by step:

That's your Java program (export it with Eclipse as a runnable jar):

public class ExtensionOpener {

    public static void main(String[] args) throws InterruptedException {

        System.out.println("args:");

        for(String arg: args) 
            System.out.println(arg);

        Thread.sleep(3000);
    }
}

That's the batch-file (just save it as eg your-starter.bat ):

@echo run bat
java -jar C:\Users\Thomas\Desktop\FileOpener.jar -file -%1

Now click right on your file ( your.fileextension ) and go to properties and associate it with the batch-file. That's it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM