Re: App running from JAR can't find files
- From: "Monique Y. Mudama" <spam@xxxxxxxxxxxxxxxx>
- Date: Tue, 18 Apr 2006 09:52:03 -0600
On 2006-04-18, Stephen Marjoribanks penned:
Monique Y. Mudama wrote:
Can you show us a code snippet of how you're trying to access the
html?
JEditorPane editorPane1 = new JEditorPane();
editorPane1.setEditable(false);
java.net.URL helpURL = HelpWindow.class.getResource("help.html");
if (helpURL != null)
{
editorPane1.setPage(helpURL);
}
else
{
editorPane1.setText("Cannot find help file");
}
I actually didn't include the html files in the Jar by mistake. However,
what confused me is that at other points in the application I load
images from an 'images' directory which isn't within the Jar but is in
the same directory as the Jar and they all work fine. Eg like this:
public void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
Image img = new ImageIcon("images/key.jpg").getImage();
g.drawImage(img, 0, 0, this);
}
What I can't quite get my head round is why the html files aren't loaded
into my application now it is run from the Jar when they worked fine
when loaded from the same relative location when running the app as
normal from the command line.
Notice that you're not using getResource() in the ImageIcon
constructor. That means that Java is looking for that file in the
filesystem, not the jar file. That's why it works.
getResource(), on the other hand, is looking in the jar file. My
guess is that you need to include the fully qualified directory for
help.html (assuming it's not right at the top of the jar file, in
which case you might try "/help.html").
--
monique
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
.
- Follow-Ups:
- Re: App running from JAR can't find files
- From: Stephen Marjoribanks
- Re: App running from JAR can't find files
- References:
- App running from JAR can't find files
- From: Stephen Marjoribanks
- Re: App running from JAR can't find files
- From: Monique Y. Mudama
- Re: App running from JAR can't find files
- From: Stephen Marjoribanks
- App running from JAR can't find files
- Prev by Date: Re: Printing MS Word from a JAVA application in a UNIX server
- Next by Date: Re: App running from JAR can't find files
- Previous by thread: Re: App running from JAR can't find files
- Next by thread: Re: App running from JAR can't find files
- Index(es):
Relevant Pages
|