如何在eclipse中将xml文件添加到java应用程序的类路径中?

时间:2023-02-09 21:52:04

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

我需要通过我正在创建的java应用程序中的类路径访问xml文件。如何在日食中实现它

3 个解决方案

#1


24  

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

我将生成一个单独的资源文件夹,右键单击它并选择“构建路径”>“用作源文件夹”。这样它就在类路径上,但是你没有将它与Java源文件混合在一起

#2


1  

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

将包含XML的目录放在运行时类路径中,然后使用className.Class.getResourceAsStream()来获取包含XML的InputStream。

#3


0  

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

将它放在java源文件夹中,并将其用作资源

#1


24  

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

我将生成一个单独的资源文件夹,右键单击它并选择“构建路径”>“用作源文件夹”。这样它就在类路径上,但是你没有将它与Java源文件混合在一起

#2


1  

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

将包含XML的目录放在运行时类路径中,然后使用className.Class.getResourceAsStream()来获取包含XML的InputStream。

#3


0  

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

将它放在java源文件夹中,并将其用作资源