简体   繁体   English

install4j6:class.getClassLoader()。getResourceAsStream(fileName)返回Null

[英]install4j6: class.getClassLoader().getResourceAsStream(fileName) returns Null

I am making an installer for my application using install4j. 我正在使用install4j为我的应用程序制作安装程序。 Previously I used install4j-5 and now using install4j 6.0.1. 以前我使用install4j-5,现在使用install4j 6.0.1。

Below problem is with install4j 6.0.1 & Works fine with install4j5 下面的问题是install4j 6.0.1&install4j5正常工作

I am calling this from a static method 我是用静态方法调用它的

Class: Util.java resourcePkgPath- "SysConfig.conf" File in Different Package 类:Util.java resourcePkgPath-“SysConfig.conf”文件在不同的包中

public static InputStream getResourceAsStream(String resourcePkgPath) { return Util.class.getClassLoader().getResourceAsStream(resourcePkgPath); public static InputStream getResourceAsStream(String resourcePkgPath) { return Util.class.getClassLoader().getResourceAsStream(resourcePkgPath); } }

When I am running my application (ie from installer) then it gives me NullPointerException but when I run the same application from command line then it works perfectly fine. 当我运行我的应用程序(即从安装程序)然后它给我NullPointerException但是当我从命令行运行相同的应用程序时,它工作得很好。 Also it runs successfully from Eclipse. 它也可以从Eclipse成功运行。

If you add the root directory to the class path of the launcher, files in it can be loaded as a resource. 如果将根目录添加到启动程序的类路径,则可以将其中的文件作为资源加载。

In previous versions, the directory of the executable was mistakenly added to the class path by default, so that's why it used to work in your case. 在以前的版本中,默认情况下,可执行文件的目录被错误地添加到类路径中,因此这就是它在您的情况下工作的原因。

If both your launcher and the "com" directory are both directly in the installation directory, add the directory "." 如果启动程序和“com”目录都直接位于安装目录中,请添加目录“。” (without the quotes) to the class path configuration of your launcher. (不带引号)到启动器的类路径配置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 class.getClassLoader getResourceasStream在jar中返回null - class.getClassLoader getResourceasStream returns null in jar 使用class.getClassLoader()。getResourceAsStream时抛出java.lang.NullPointerException - java.lang.NullPointerException throws while using class.getClassLoader().getResourceAsStream Java getClassLoader()。getResourceAsStream(文件名) - Java getClassLoader().getResourceAsStream(filename) Java:无法弄清楚如何使用class.getClassLoader()。getResourceAsStream(),因此在构建工件时可以使用 - Java: Can't figure out how to use class.getClassLoader().getResourceAsStream() so it works when i build artifacts getClassLoader()。getResourceAsStream方法为具有“.LIB”扩展名的文件返回null - getClassLoader().getResourceAsStream method returns null for a file with “.LIB” extension getClass().getClassLoader().getResourceAsStream() 总是返回 null,资源在 application.jar 中 - getClass().getClassLoader().getResourceAsStream() always returns null, resource is in application.jar 如果 cp 不以冒号结尾,为什么 class.getClassLoader() 会抛出 null 指针? - Why class.getClassLoader() throws null pointer if cp do not end with a colon? 如何指定class.getClassLoader()返回哪个类加载器? - How to specify which class loader should class.getClassLoader() return? this.getClass()。getClassLoader()。getResourceAsStream始终返回null - this.getClass().getClassLoader().getResourceAsStream always returning null getClassLoader().getResourceAsStream(resource) 在 java 中返回 null 11 - getClassLoader().getResourceAsStream(resource) return null in java 11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM