1

I have a jar file that contains two files in the root
tbs.jar
-parser.dat
-MapScript.txt
I've tried to access them with:
getClass().getResource("parser.dat")
and I also tried:
getClass().getResource("/parser.dat")
but neither works. The class that I'm using, the class I call "getClass" on, belongs to a package that lies in the same jar. So how am I supposed to refer to the files in the same jar, should I perhaps try "../parser.dat"? Nothing I try seems to work.

Dude Dawg
  • 1,465
  • 2
  • 15
  • 26
  • 2
    getClass().getResource("/parser.dat") should work. Show us the code you're using to access the resource. – JB Nizet Aug 14 '11 at 21:07

1 Answers1

1

try replacing

getClass().getResource("parser.dat") 

with

getClass().getClassLoader().getResource("parser.dat")
  • @eon If I am trying same thing using command line what things I need to do -jar myjar.jar config/spring-context.xml myJob argu1 argu2 spring-context.xml file contains inside config folder inside jar. – Kamini Jun 04 '17 at 06:45
  • @Kamini see Jon Skeet's post here https://stackoverflow.com/questions/6068197/utils-read-resource-text-file-to-string-java –  Jun 04 '17 at 12:20