如何在Eclipse中引用不在src中的文件 [英] How to reference a file in Eclipse that is not in src

查看:212
本文介绍了如何在Eclipse中引用不在src中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取MyBatis的资源.本教程指出,在连接工厂中我将需要以下内容:

I'm trying to get a resource for MyBatis. The tutorial states that I will need the following in my Connection Factory:

String resource = "org/mybatis/example/Configuration.xml";
Reader reader = Resources.getResourceAsReader(resource);
sqlMapper = new SqlSessionFactoryBuilder().build(reader);

我的目录结构是:

src/ com/ 实用程序/ MyBatisConnectionFactory.java 配置/ Configuration.xml

src/ com/ utils/ MyBatisConnectionFactory.java config/ Configuration.xml

我在引用配置文件时遇到麻烦.我尝试了"config/Configuration.xml","Configuration.xml"和"/config/Configuration.xml".

I am having troubles referencing the configuration file. I tried "config/Configuration.xml", "Configuration.xml" and "/config/Configuration.xml".

每个人都有一个做什么的好主意吗?

Anyone have a good idea for what to do?

推荐答案

您可以将config目录添加为源文件夹(右键单击>构建路径>用作源文件夹).

You can add your config directory as a source-folder (right-click > build path > use as source folder).

因此,您的配置文件将位于类路径的根目录上,并且可以通过getClass().getResourceAsStream("/Configuration.xml")

Thus your configuration files will go on the root of the classpath and will be accessible via getClass().getResourceAsStream("/Configuration.xml")

这篇关于如何在Eclipse中引用不在src中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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