简体   繁体   中英

How to add PDF files as resources inside an executable JAR

after many days of searching here and in google, and after many tries, i have finally decided to open an account for help.

Workspace environment: Latest Java version, Windows 8.1, Eclipse Luna

what i want to happen: lunch my application from an executable jar, click a specific button and have a PDF file open.

up until now, i can do all that and it works... , except.

what actually happens: my PDF folder is 20 MB and my jar file is 11 KB, and when i copy my jar file to desktop, lunch the jar file and click the button, no pdf file is opened.

my question is:

how can i integrate the files into the jar?

i have res folder for resources, i have heard of InputStream, FileReader, BufferReader, but cannot figure out how implement them in the code (i have tried, so many many times). currently, i am using

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filePath);

in order to open the file right now, but it's not a permanent solution since there is no integration and no portability.

please, this is the final step for my application. i cannot rest until it's finished.....

尝试在命令行上输入以下内容:

Jar uf [your jar] res/afile.pdf

i have realized that all i needed to do for portability was to bundle the jar file and resource file in the same folder, and that was it. in fact, having the resource file accessible was far better than having it in the jar (keeping the jar now at only 13 KB), thus, allowing me to edit the resource folder as i see fit is way more flexible.

thank you all for your patient and the willing to help.

this question can be closed now.

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