JApplet in Jar file can only be run from html contained in Jar file
I have a JApplet that is based off an application. I need it to read in a text based file containing all of it's data. So I stuck it in the Jar file and everything became happy in AppletViewer.
Unfortunately not everything is happy in browser land.
When I try to run the applet in a browser from a html page which is not in the jar, then I get the good old: java.security.AccessControlException: access denied (java.io.FilePermission
(it then lists the location of the jar on my filesystem and the !resource address)
But if I open the jar file up in a zip extractor/viewer like winzip and open the page that launches the applet (that I put inside the jar) it works fine. As expected, it can only access resources that have the same host, which seems in this case to come right down to the jar file itself.
SO my question is WTF? Can I o开发者_如何学Pythonpen the html file inside the jar file from a browser... even inside an iframe or anything would be ok, as long as it doesn't further mess up the permissions.
Or can I call the applet from a html page outside the jar? I'm not using JNLP right now, cos I wanted to cobble together a prototype applet ASAP.
<applet code = 'CatalogApplet'
archive = 'ContactCatalog.jar',
width = 1000,
height = 800 />
Is the entirity of the HTML call to the applet.
I'm not going to sign it, because it really shouldn't need signed. I am just wanting to call back to jar.
The file should be accessed via URL, not by FileInputStream. Use this to get the URL:
URL urlToText = this.getClass().getResource("path/to/the.html");
That will work in a sand-boxed applet.
the clean way is : package your ".class" files in a jar . have an html file outside the jar that references your jar inside applet tag. if your applet requires access to user filesystem then the right way to go is to sign your applet jar. see http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html
精彩评论