简体   繁体   中英

Exporting Project into a Runnable JAR File with PDF document

I have project that I created and it contains a help button that opens a .pdf file with my documentation. The code for the button is the following

URL loc = Actions.class.getResource("Documentation/test.pdf");
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + loc);

When I run and execute my application using eclipse and click on the button it opens the document fine in adobe reader. After I export my project into a Runnable JAR File via eclipse and click on the button it doesn't do anything. Is there something that I need to add in order to make this work?

I just opened the jar file using 7zip and my test.pdf document does show up in there.

The default behavior and intentions behind a jar file are for packaging of files (Java) into a compressed format. If you want to have an executable type jar then you need to include a manifest file that specifies your main Java class (the class that contains the main() . From here you can code the logic to launch your pdf's.

This may be because the pdf file is inside the jar and returned URL from method getResource can not be recognized by external program.

You can do a print of " loc " to see what the URL looks like when it's in the jar file.

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