java - Loading a local html file on jar into web engine -


i'm having problem in loading html file application onto web engine.

currently, if run application throw intellij ide. html page being loaded correctly! when make project , run application terminal. html file isn't being loaded @ all.

my code loading html page web engine.

webengine = wv.getengine(); we.setjavascriptenabled(true); string htmlfile = getclass().getresource("/html/index.html").toexternalform(); system.out.println(">>>"+htmlfile); we.load(htmlfile); 

why have println ? check path of html page. seems when run on project intellij. application runs correctly. shown under:

>>>file:/developer/liss-sde/out/production/liss/html/index.html 

but when on terminal. prints me don't understand.

>>>jar:file:/users/damien/desktop/liss%7csde/liss.jar!/html/index.html 

why put jar: @ beginning? why putting ! program .jar ? , if compare other print, totally different!

i extracted .jar file check if directory , html file missing, ok. problem having?

the name of file, jar: , !, url file in jar, defined in jarurlconnection. using getresource() on showing file correctly. use getresourceasstream() access file contents, should enough in case.

you can direct access contents of jar using java jar api. there introduction couple of examples @ java2s tutorial page. jars in class path (which seems case time) jar api used automatically within getresource() , getresourceasstream() methods of class.

from java 7 onwards, filesystem api has been available , hides of more awkward details. oracle technote gives concise introduction api , how use it.

snippet page, tweaked case:

import java.util.*; import java.net.uri; import java.nio.file.path; import java.nio.file.*;  public class whatsinmyjarfile {     public static void main(string [] args) throws throwable {         // locate file system using syntax          // defined in java.net.jarurlconnection         uri uri = uri.create("jar:file:/users/damien/desktop/liss%7csde/liss.jar");         try (filesystem jarfs = filesystems.newfilesystem(uri)) {             path pathinjarfile = jarfs.getpath("/html/index.html");             dostuff(files.newinputstream( pathinjarfile ));         }      } } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -