How to include resource folder in executable .jar file in eclipse?

廉价感情. 提交于 2020-01-24 09:57:04

问题


I need to create an application for sorting various types of polygons using various parameters such as height, volume or base area. Arguments for Filename which has parameters for polygons, Sort type, Sort method will be pass through command line.That file is in my resource folder outside my src folder in a project. I have implemented all programs, It works fine when I run using pass arguments through eclipse run configuration. But when I try to run my .jar file using cmd same arguments it gives me FileNotFoundException.

I opened my jar file using 7zip and noticed it never extracted my resource folder in .jar file. I searched online and tried including my resource folder in to build path of eclipse. But still does't work.


回答1:


Follow these steps:

1) click project -> properties -> Build Path -> Source -> Add Folder and select resources folder.

2) create your JAR!

EDIT: you can make sure your JAR contains folder by inspecting it using 7zip.

Reefer this link as well How do I add a resources folder to my Java project in Eclipse




回答2:


This comes down to how you are generating the JAR file.

When you're exporting the jar in eclipse make sure to checkbox the button that says "Export java sources and resources" https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/ensureJavaFiles.jpg

There are a lot of ways to do this one is to use Gradle is the recommended way, something like this will work Creating runnable JAR with Gradle



来源:https://stackoverflow.com/questions/47100605/how-to-include-resource-folder-in-executable-jar-file-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!