[英]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.html
和style.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.