有没有一种简单的方式在Eclipse中的java项目中使用XML资源? [英] Is there a simple way to use XML resources within a java project in Eclipse?

查看:208
本文介绍了有没有一种简单的方式在Eclipse中的java项目中使用XML资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用java解析XML文件 - 好,很容易。如果我可以使用我在同一Eclipse项目中的文件夹中创建的XML文件(让我们称之为resources文件夹),这将是非常好的。由于版本控制,多个开发平台和一般简单性的问题,拥有此功能非常好,而不是访问文件系统中的文件。



有没有一个简单的方法来做到这一点,也许是不需要下载/安装附加包的呢?这是一个学校任务,规则是我们可以使用IDE附带的任何库或类,但就是这样。使用非标准库是欺骗。

解决方案

你可以这样做了。 (如果我明白你的问题。)



如果你有一个这样的Eclipse项目:

 项目
src
java.packages
resources
xmlfiles.xml

您可以像这样访问xml文件:

 文件f = new File资源/ yourXmlFile.xml); 

这样你就不必担心文件在文件系统上的位置。 / p>

查看 StackWrap4J 项目设置。这很可能与你想要的相同:




I'd like to parse through XML files with java - ok, easy. It would be REALLY nice if I could use an XML file that I've created within a folder inside my same Eclipse project (let's call it the "resources" folder). Due to issues with version control, multiple development platforms, and general simplicity, it would be VERY, VERY nice to have this capability, rather than accessing the file in the file system.

Is there an easy way to do this, perhaps one that doesn't require downloading/installing additional packages? It's for a school assignment, and the rule is that we can use any library or class that comes with the IDE, but that's it. Using a "nonstandard" library is cheating.

解决方案

You can do this already. (If I understand your question.)

If you have an Eclipse project like so:

Project
    src
        java.packages
    resources
        xmlfiles.xml

You can access the xml files like so:

File f = new File("resources/yourXmlFile.xml");

That way you don't have to worry about where the files are exactly on the file system.

Have a look at the StackWrap4J project setup. It is most likely identical to what you want:

这篇关于有没有一种简单的方式在Eclipse中的java项目中使用XML资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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