0

I have a set of help files for my SWT application that I have open in-application using the Browser control. Navigation through the help files is done through hyperlinks of relative pathnames (i.e: <a href="aboutUs.htm">, so only one html file is actually opened by java code, helpHome.htm. I am opening this using String homeURL = this.getClass().getResource("/help/helpHome.htm").toString(); and browser.setURL(homeURL); This works beautifully when I'm just debugging it in Eclipse. Unfortunately, when I move the project into a .jar, the browser gives the standard "can't find this webpage" error. I've tried using the browser.setText(String); function as described in this link, which works for helpHome.htm, but when I click a hyperlink, it brings me to a blank page displaying the relative pathname. Is there a way to convince browser to open an html file from an executable jar using the setURL(String) method? If not, are there any suggested workarounds for me to achieve similar results?

Thanks in advance!!

Community
  • 1
  • 1
connory3
  • 45
  • 2
  • 4
  • As long as you're running inside Eclipse, the application is _not_ packaged as a jar file and the files are accessible directly via the file: URL scheme. Once you're using your application via a jar file, then the URL for the browser must refer to a member to a file entry of that jar file. And I highly doubt that the Browser widget understands this scheme... – Tonny Madsen Jun 15 '13 at 12:38
  • Thanks for the answer. That's kind of what I suspected I just wanted to make sure I wasn't missing anything – connory3 Jun 18 '13 at 22:06

1 Answers1

0

You have to start an internal Server as explained here on any available port on your application start up and make your html files available as static resources to the server.

Then set the browser.setURL(homeURL). All the subsequent hyperlinks will now point to the server, which knows how to serve the requested resources.

The hyperlinks are resolved to File System Path (Ex. file://C:\workspace....) while you are running or debugging your application in eclipse and things were working fine then. But that is not the case when you run your app from a runnable jar.

Niranjan
  • 1,776
  • 1
  • 13
  • 21
  • Thanks for the answer, I'm working on implementing it now. I'm not sure I understand it completely though. I can't use browser.setURL(homeURL) as of right now because it can't find the page. Unless you have an alternative way to initialize homeURL? Sorry if I'm asking silly questions. – connory3 Jun 18 '13 at 22:09
  • @connory3 once you start setting up the internal server, you'll automatically come to know what url to set on the `SWTBrowser` – Niranjan Jun 18 '13 at 22:39