如何将图像和xml文件上传到eclipse中的maven项目中 [英] How to upload images and xml file into a maven project in eclipse

查看:150
本文介绍了如何将图像和xml文件上传到eclipse中的maven项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和我的朋友进行一场电视游戏。我们正在使用Eclipse,我们正在使用maven。我们使用BitBucket同步该项目,但现在我们有一个问题。我正在做GUI,但是我不知道如何在项目中上传图像和一个xml文件,并将其与bitbucket进行同步。现在我正在使用桌面上文件的路径。有一种方法来加载所有文件并将其导入到项目中?当我们必须将项目导出到jar文件中时,我正在搜索一个正确的解决方案。

解决方案

将文件放在源文件夹资源中,并将它们不作为文件访问,但作为

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

或直接作为:

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

区分大小写。



这些文件与jar文件中的.class代码一起。


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.

解决方案

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.

这篇关于如何将图像和xml文件上传到eclipse中的maven项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆