Java 在Jar文件中获取xml文件

Java 在Jar文件中获取xml文件,java,xml,exception,jar,static-methods,Java,Xml,Exception,Jar,Static Methods,我正在使用NetBeans,在其他线程的帮助下,我编写了这个函数来解决同一个问题, 但我得到的行InputStream的错误是=getClass.getResourceAsStreamxml\u file\u path; 说明:无法从静态上下文引用非静态方法getClass 我能做什么? 我尝试使用ClassLoader,但没有成功 non-static method getClass() cannot be referenced from a static context 您必须使用: Yo

我正在使用NetBeans,在其他线程的帮助下,我编写了这个函数来解决同一个问题, 但我得到的行InputStream的错误是=getClass.getResourceAsStreamxml\u file\u path; 说明:无法从静态上下文引用非静态方法getClass

我能做什么? 我尝试使用ClassLoader,但没有成功

non-static method getClass() cannot be referenced from a static context
您必须使用:

YourClass.class.getResourceAsStream()
而不是getClass

您必须使用:

YourClass.class.getResourceAsStream()
代替getClass。

尝试以下操作:

InputStream is = YourClass.class.getClassLoader().getResourceAsStream(xml_file_path);
试试这个:

InputStream is = YourClass.class.getClassLoader().getResourceAsStream(xml_file_path);
大量重复:大量重复: