在运行时查找打包的非java文件的路径

时间:2022-05-10 13:25:34

So this might be a stupid question but...

这可能是个愚蠢的问题,但是…

I want to package a specific WSDL file in with an EJB project within eclipse. What would be the best way to refer to this file in my code?

我希望将特定的WSDL文件与eclipse中的EJB项目打包在一起。在我的代码中引用这个文件的最佳方式是什么?

I would like to use a relative path but the current directory starts off in the /bin directory of my JBOSS installation. It seems like there should be a way to refer to the file in relation to the project file structure.

我想使用一个相对路径,但是当前目录从JBOSS安装的/bin目录开始。似乎应该有一种方法来引用与项目文件结构相关的文件。

Any ideas?

什么好主意吗?

1 个解决方案

#1


1  

getClass().getResource(String path) uses a relative path to locate a classpath resource. It returns a java.net.URL. Alternatively, you can use getResourceAsStream(..) to obtain the InputStream to the resource.

getClass()。getResource(字符串路径)使用相对路径来定位类路径资源。它返回一个java.net.URL。或者,您可以使用getresourcesstream(.)来获取资源的InputStream。

#1


1  

getClass().getResource(String path) uses a relative path to locate a classpath resource. It returns a java.net.URL. Alternatively, you can use getResourceAsStream(..) to obtain the InputStream to the resource.

getClass()。getResource(字符串路径)使用相对路径来定位类路径资源。它返回一个java.net.URL。或者,您可以使用getresourcesstream(.)来获取资源的InputStream。