0

I created a jar file in my working folder

jar -cfe MRMC.jar MRMC *.class *.jar DB statpack

and I am able to double click the jar file or run it using java -jar MRMC.jar

But when I copy the jar file to another location, I can no longer run it. I got errors:

Exception in thread "main" java.lang.NullPointerExeption

it seems that the jar file did not find files in the resource folder DB above.

Thank you.

Xin He
  • 11
  • 1
  • Are the classes in the jar referencing files relative to the jar's original location? – Cliff Mar 09 '12 at 21:59
  • you say "it seems that the jar file did not find files in the resource folder DB above." so you need to copy resources to the new location of the jar as well, don't you? – Juvanis Mar 09 '12 at 21:59

1 Answers1

0

I see two possible reasons:

a) the content of the DB directory does not end up in the jar. Unzip the jar to check what is actually inside. Note: a jar is just a zipfile.

b) you are not referencing the files as a classpath resource, but as a File Resource. Check the methods you are using, if they are based on the classpath or on the file system.

See this question for the different ways to load a file: How should I load files into my Java application?

Community
  • 1
  • 1
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348