Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » HTML files in runnable JAR
HTML files in runnable JAR [message #734477] Fri, 07 October 2011 22:45 Go to next message
RD  is currently offline RD Friend
Messages: 10
Registered: September 2011
Junior Member
I am trying to package an HTML file in a runnable JAR.

My code to access the file:
URL url = this.getClass().getResource("XConManual.htm"); 
browser.setUrl(url.toString());


This works in Eclipse, but running the JAR file doesn't work.

To export, I go:
Export->Runnable JAR File (package libraries into generated JAR).

I noticed that url.toString() returns a path to my local drive where the HTML file is located.

What am I doing wrong?

[Updated on: Fri, 07 October 2011 22:46]

Report message to a moderator

Re: HTML files in runnable JAR [message #734530 is a reply to message #734477] Sat, 08 October 2011 07:22 Go to previous messageGo to next message
job78ail  is currently offline job78ail Friend
Messages: 2
Registered: October 2011
Junior Member
I am having same issues, can someone reply to post please?
Re: HTML files in runnable JAR [message #734570 is a reply to message #734477] Sat, 08 October 2011 16:45 Go to previous messageGo to next message
Dilton McGowan II is currently offline Dilton McGowan IIFriend
Messages: 110
Registered: July 2009
Senior Member
On Fri, 07 Oct 2011 18:45:42 -0400, RD wrote:

> I am trying to package an HTML file in a runnable JAR.
>
> My code to access the file:
> URL url = this.getClass().getResource("XConManual.htm");
> browser.setUrl(url.toString());
>
> This works in Eclipse, but the running the JAR file doesn't work.
>
> To export, I go:
> Export->Runnable JAR File (package libraries into generated JAR).
>
> I noticed that url.toString() returns a path to my local drive where the
> HTML file is located.
>
> What am I doing wrong?

As long as the HTML file is locatable on the classpath then
it should work. For a test to prove this, move the file to
the location of your class. Later if it's more convenient you
can use a path to locate it like "/the/html/classpath/file.html".
Re: HTML files in runnable JAR [message #735099 is a reply to message #734570] Mon, 10 October 2011 22:54 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Unless your browser knows how to read and show an HTML file from inside a JAR file, it won't work inside a Runnable JAR. Perhaps you should clarify what you mean by "doesn't work"?

_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: HTML files in runnable JAR [message #735376 is a reply to message #735099] Tue, 11 October 2011 15:52 Go to previous messageGo to next message
RD  is currently offline RD Friend
Messages: 10
Registered: September 2011
Junior Member
I'm not trying to use an external browser to read the HTML. I'm using an SWT browser widget within my application to display the HTML. Problem is that when deploying the runnable JAR, my application can't find the HTML file. When running it in Eclipse, the application finds it and displays it just fine.

I have the HTML file in the same directory as the .java files.
Re: HTML files in runnable JAR [message #735438 is a reply to message #735376] Tue, 11 October 2011 19:20 Go to previous message
RD  is currently offline RD Friend
Messages: 10
Registered: September 2011
Junior Member
Ok I found an answer in another forum:

InputStream in = getClass().getResourceAsStream("XConManual.htm");
		Scanner scanner = new Scanner(in);
		StringBuffer buffer = new StringBuffer();
		while(scanner.hasNextLine()) {
		    buffer.append(scanner.nextLine());
		}

		browser.setText(buffer.toString());


Problem is that now the XConManual.htm can't find the image files and other files that it links to.
Previous Topic:Dual Installation JavaDoc
Next Topic:problem installing Eclipse - failed to find a Main class in ..
Goto Forum:
  


Current Time: Thu Apr 25 04:21:17 GMT 2024

Powered by FUDForum. Page generated in 0.08231 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top