Skip to main content



      Home
Home » Newcomers » Newcomers » HTML files in runnable JAR
HTML files in runnable JAR [message #734477] Fri, 07 October 2011 18:45 Go to next message
Eclipse UserFriend
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 18:46] by Moderator

Re: HTML files in runnable JAR [message #734530 is a reply to message #734477] Sat, 08 October 2011 03:22 Go to previous messageGo to next message
Eclipse UserFriend
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 12:45 Go to previous messageGo to next message
Eclipse UserFriend
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 18:54 Go to previous messageGo to next message
Eclipse UserFriend
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"?
Re: HTML files in runnable JAR [message #735376 is a reply to message #735099] Tue, 11 October 2011 11:52 Go to previous messageGo to next message
Eclipse UserFriend
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 15:20 Go to previous message
Eclipse UserFriend
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: Mon Jul 14 08:13:55 EDT 2025

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

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

Back to the top