简体   繁体   中英

Embed HTML in JAR with Eclipse

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?

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 Package method, java used to look for style.css in the root of the JAR file, no matter where the HTML file was located.

导出菜单

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM