簡體   English   中英

使用Eclipse將HTML嵌入JAR中

[英]Embed HTML in JAR with Eclipse

我已經讀過這個問題,但是仍然沒有運氣。

我想將HTML頁面嵌入CSS文件。 在我的項目中,我有res文件夾,在.classpath我有<classpathentry kind="src" path="res"/>以便嵌入我的文件。

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

CTLiner.java是主類文件。

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

我使用此代碼加載index.html 如果我從Eclipse運行此命令,則會得到以下輸出

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

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

效果很好。 當我將項目導出為Runnable JAR時,代碼輸出:rsrc:html / index.html並且找不到CSS文件。

我相信,如果我將index.htmlstyle.css文件上移(我可以這么說嗎?),一切都會正常進行,但是還有其他解決方案嗎?

我在Package required libraries into generated JAR使用了Package required libraries into generated JAR ,但是我不得不在Extract required libraries into generated JAR使用了Extract required libraries into generated JAR 我不知道為什么。

當我使用Package方法時,無論HTML文件位於何處,java都會在JAR文件的根目錄中查找style.css

導出菜單

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM