1

I've already read this question, but still no luck.

I want to embed HTML pages with CSS files. In my project I have res folder, in .classpath I have <classpathentry kind="src" path="res"/> so that my files are embedded.

|-- src
|   `-- com
|       `-- pkg
|           `-- blahblahblah
|               `-- CTLiner.java
`-- res
    `-- html
        |-- index.html
        `-- style.css

CTLiner.java is main class file.

URL u = CTLiner.class.getResource("/html/index.html");
System.out.println(u.toURI().toString());
webView.showPage(u);

I use this code to load index.html. If I run this from Eclipse I get the following output

file:/home/user/workspace/CTLiner/bin/html/index.html

And

<link href="style.css" rel="stylesheet" type="text/css" />

Works great. And when I export project as Runnable JAR, code outputs: rsrc:html/index.html And CSS file isn't found.

I believe that if I move index.html and style.css files up-tree (can I say so?) everything will work, but is there any other soltion?

Community
  • 1
  • 1
Ilgiz Mustafin
  • 414
  • 1
  • 4
  • 15
  • Try to put it under src/main/resources? – TungstenX Dec 05 '14 at 10:17
  • @TungstenX works the same if I understood what you meants. – Ilgiz Mustafin Dec 05 '14 at 10:24
  • I found that it is easier to put it where your IDE/compiler wants it than to fight with it ;) Have you looked at the content of the JAR file? (using winrar or winzip, etc) – TungstenX Dec 05 '14 at 10:27
  • Yep. If I do everything like I mentioned in the question, the `html` folder appears in the root of the JAR. I don't know how to check where it searches for `style.css`. Oh, wait. I know, gonna check. – Ilgiz Mustafin Dec 05 '14 at 10:42
  • @TungstenX It looks in the root of the JAR. – Ilgiz Mustafin Dec 05 '14 at 10:46
  • Thus index.html is in /html but styles.css is in / ? The index.html is looking for it in its own directory, that is /html – TungstenX Dec 05 '14 at 11:03
  • I thought so too, buuut no. I have style in `/` and html in `/html/index.html`. Finally solved. The problem was Library handling option in export menu. Going to post answer now =) – Ilgiz Mustafin Dec 05 '14 at 11:06

1 Answers1

2

I was using the Package required libraries into generated JAR, but I had to use Extract required libraries into generated JAR. I don't know why yet.

When I used the Packagemethod, java used to look for style.css in the root of the JAR file, no matter where the HTML file was located.

Export  menu

Ilgiz Mustafin
  • 414
  • 1
  • 4
  • 15