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 = Ac开发者_如何学运维tions.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.
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 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.
精彩评论