How to upload images and xml file into a maven project in eclipse

懵懂的女人 提交于 2019-12-25 03:58:22

问题


I'm working on a videogame with a my friend. We are working with Eclipse and we are using maven. We use BitBucket to synchronize the project but now we have a problem. I'm doing the GUI but I don't know how to upload the images and an xml file in the project and synchronize this with bitbucket. Now I'm using the path of the file that is on my desktop. There is a way to load all the files and import these into the project? I'm searching a solution that is correct also when we must export the project in a jar file.


回答1:


Place the files in the source folder resources, and access them not as File, but as

URL url = getClass().getResource("/a/b/c.png");
// URL "..... myproject.jar!/a/b/c,png"

or direct as:

InputStream in = getClass().getResourceAsStream("/d.xml");

Case-sensitive.

This zips the files together with the .class code in the jar file.



来源:https://stackoverflow.com/questions/24206646/how-to-upload-images-and-xml-file-into-a-maven-project-in-eclipse

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