问题
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