Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regarding Help File in JAVA

Tags:

java

I'm new to help file creation in java. I have created a help file "sample.chm" with a 3rd party tool, added it to a java program with package name as "help" calling with runtime class and build the jar. When I run the jar file it is giving me an error that the "file cannot be found, null pointer Exception". I have given a relative path to identify the file like "../help/sample.chm" still it is not working and I tried with various classes to ientify the path. But still the same error.

Request you to please help me in fixing it.

The jar can be placed in different systems and should open this help file with out any issues.

I hope my explanation is sufficient you to identify the problem.

Regards,

Chandu

like image 276
Chandu Avatar asked Sep 18 '26 17:09

Chandu


1 Answers

If you have a file inside a jar, you can't access it as you normally would. You can access it like this:

URL helpFile=Thread.currentThread().getContextClassLoader().getResource("help/sample.chm");

The method used above (getResource) will return a URL; if you want, you can get it as an InputStream as well by using getResourceAsStream instead.

like image 95
qmega Avatar answered Sep 21 '26 05:09

qmega