NullPointerException when reading a file in jar during Process Designer Testing?

When we need to call a java jar in Process Designer, we can use both java or javascript. But sometimes we may have the following error shows: [4/25/18 17:21:07:102 GMT+08:00] 0000028f wle E CWLLG2015E: An unexpected runtime exception occurred. See exception for more details. Error: com.wanhua.ldap4vue.utils.PropUtils (initialization failure). java.lang.NoClassDefFoundError: com.wanhua.ldap4vue.utils.PropUtils (initialization failure) at java.lang.J9VMInternals.initialize(J9VMInternals.java:176) at ..... Caused by: java.lang.NullPointerException at com.wanhua.ldap4vue.utils.PropUtils.(PropUtils.java:34) at java.lang.J9VMInternals.initializeImpl(Native Method) at java.lang.J9VMInternals.initialize(J9VMInternals.java:236) ... 93 more

And we can see the code and found some files in the jar can not be read using following method: Thread.currentThread().getContextClassLoader().getResources("file.properties")；

1 reply

The method used to call the file may not work because the current thread is not the same thread to execute the jar file. You should use the absolute path of the file or use the following method: this.getClass().getClassLoader().getResourceAsStream("test.properties");