aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Little question on accessing files in a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Little question on accessing files in a jar" Watch "Little question on accessing files in a jar" New topic
Author

Little question on accessing files in a jar

Juan Katabasis
Ranch Hand

Joined: Jun 20, 2001
Posts: 46
good night colleagues
a stupid question, but i have made searches in old posts and could not find response.
i'd like to have in my executable jar (both for client and server) the html files for the online help my application uses, but i can't make this work, the system is not able to find the help/index.html file unless i put outside the jar.
any advise please?
thank you very much
[ November 02, 2002: Message edited by: Jaun Katabasis ]

Regards<br />J.
Juan Katabasis
Ranch Hand

Joined: Jun 20, 2001
Posts: 46
i've resolved the problem
thanks anyway
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Jaun,
could you please let me know how you solved the problem?
Thank you!


Mag
Juan Katabasis
Ranch Hand

Joined: Jun 20, 2001
Posts: 46
Hello
my jar test file has 'help' and 'suncertify' (and META-INF) as directories.
helpURL = ClassLoader.getSystemResource (HELP_FILE_NAME)
where HELP_FILE_NAME is defined in ClientConstantsI and values "help/hlp.html" works ok
but for some reason, if i provide to getSystemResource an argument something like
HELP_FILE_DIR + System.getProperty("file.separator") + HELP_FILE_NAME
( this is, "help\\hlp.html" )
it will work ok if executed in uncompressed directories but not inside the jar. that was my initial problem.
i don�t like the solution, as hardcoding "/" as file separator goes against portability, but i can�t find a better solution.
[ November 04, 2002: Message edited by: Jaun Katabasis ]
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Jaun,
thank you for the hint! I'll try it.
Regarding the slash "/", try this:

I usually assign the return value to a constant in an interface, which contains all sorts of constants and is available to the application as a whole.
Hope this helps.
[ November 04, 2002: Message edited by: Mag Hoehme ]
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Jaun,
I found out how to view HTML files packed into a jar file. check out my exemplary JarBrowser at
http://www.mhoehme.de/java/jarbrowser/index.html.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Little question on accessing files in a jar