how to add an xml file to the java application's classpath in eclipse?

风流意气都作罢 提交于 2019-12-05 11:21:29

问题


I need an xml file to be accessed via the classpath in a java application i am creating . how to achieve it in eclipse


回答1:


I'd generate a separate resources folder, right-click it and select Build Path > Use as Source Folder. That way it's on the class path, but you're not mixing it with your Java source files




回答2:


Put the directory containing the XML in the runtime classpath, then use className.Class.getResourceAsStream() to get an InputStream containing the XML.




回答3:


Put it in java source folder, and use it as resource



来源:https://stackoverflow.com/questions/5832064/how-to-add-an-xml-file-to-the-java-applications-classpath-in-eclipse

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