0

Same lines of code work in Windows but not in Linux. Code is run through a executable jar file.

  • Entries in BuildPath: {PROJECT}/src,{PROJECT}/res
  • Project Path of Test1.java: /src/com/qe/util/Test1
  • Project Path of TC_Mapping.xml: /res/TC_Mapping.xml

.

package com.qe.util;
public class Test1{
    public static void parseTCMapping(){
    ...
        String xmlPath = TCDetailsExtractor.class.getClassLoader().getResource("TC_Mapping.xml").toString();
        System.out.println(xmlPath);
        InputStream is = TCDetailsExtractor.class.getClassLoader().getResourceAsStream(xmlPath);
    ...
    }
}
eis
  • 51,991
  • 13
  • 150
  • 199
kk.
  • 667
  • 1
  • 15
  • 33

1 Answers1

0

If you have resource in jar you should use getResourceAsStream() method to obtain its content. This might when files are not in jar but not when application is packed in jar.

ps-aux
  • 11,627
  • 25
  • 81
  • 128
  • I am already doing this at [TCDetailsExtractor.class.getClassLoader().getResourceAsStream(..)], the issue is this line of code works in Win but not in linux. InputStream is always set to null. – kk. Nov 21 '16 at 08:25