简体   繁体   English

使用Eclipse将HTML嵌入JAR中

[英]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. 我想将HTML页面嵌入CSS文件。 In my project I have res folder, in .classpath I have <classpathentry kind="src" path="res"/> so that my files are embedded. 在我的项目中,我有res文件夹,在.classpath我有<classpathentry kind="src" path="res"/>以便嵌入我的文件。

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

CTLiner.java is main class file. CTLiner.java是主类文件。

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 . 我使用此代码加载index.html If I run this from Eclipse I get the following output 如果我从Eclipse运行此命令,则会得到以下输出

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. 当我将项目导出为Runnable JAR时,代码输出:rsrc:html / index.html并且找不到CSS文件。

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? 我相信,如果我将index.htmlstyle.css文件上移(我可以这么说吗?),一切都会正常进行,但是还有其他解决方案吗?

I was using the Package required libraries into generated JAR , but I had to use Extract required libraries into generated JAR . 我在Package required libraries into generated JAR使用了Package required libraries into generated JAR ,但是我不得不在Extract required libraries into generated JAR使用了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. 当我使用Package方法时,无论HTML文件位于何处,java都会在JAR文件的根目录中查找style.css

导出菜单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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