1

I'm currently trying to write a little application (Which doesn't require internet access - So it really only is a local application.), which should be kept really simple. I thought about simply using HTML(+CSS) and a bit of JavaScript, since that would largely be sufficient, but I also need to have access to the filesystem in order to store my data in some file, which isn't really possible in javascript (Yes, I crawled through quite a few posts about JavaScript & FileSystem, but I didn't like any of the solutions.)

So I thought about another way to do it: There is some nice Library called HtmlUnit which would allow me to basically simulate my JavaScript, while having the Java FileAccess - But then I won't be able to render it.

So, two questions:

  1. Is it possible to somewhat declare a JavaScript File as "local" and thus gaining file-system permissions?

  2. Many applications (Games etc) internally use Internet Explorer. Is it possible to use IEs (Or even Chromes/Firefoxes/Whatevers) renderer in Java? I don't like any of the rendering-libraries I found until now - Or just simply be able to execute js+html code as a local application?

  3. I tried out .HTAs, and I absolutly hate them. It's just so... old. Nothing is possible there. It would be awesome to get a simple html/js application looking like in chrome, but being a local application.

Fly
  • 810
  • 2
  • 9
  • 28

3 Answers3

2

Q&A

  1. Is it possible to somewhat declare a JavaScript File as "local" and thus gaining file-system permissions?

No, it is only possible through ActiveX / plugins (e.g. Java / browser addon).

Others may suggest that JavaScript has data storage or file system. But they are not local file system access, and you cannot read or write real files with them.

  1. Many applications (Games etc) internally use Internet Explorer. Is it possible to use IEs (Or even Chromes/Firefoxes/Whatevers) renderer in Java? I don't like any of the rendering-libraries I found until now - Or just simply be able to execute js+html code as a local application?

JavaFX's WebView use WebKit as renderer. Webkit is not a full browser, so it has less feature, e.g. no localStorage, but you can replace most of them with Java code.

SWT Browser, as mentioned by another answer, also works as renderer but will make it difficult for you to package as single file, plus it depends on client to do install/update the browser.

  1. I tried out .HTAs, and I absolutly hate them. It's just so... old. Nothing is possible there. It would be awesome to get a simple html/js application looking like in chrome, but being a local application.

It is possible to embed all resources into one HTML file using inline code and data uri. Here is one of my projects that does it: [source files] [single file deployable].

Regardless, most browsers does not allow file write, as you no doubt already know, and Chrome is especially hostile against file access.


Advise

From my experience, the only feasible solutions are:

  1. ActiveX HTML app
  2. Native program, such as Java jar or .Net exe. (Or a jar packaged as exe)
  3. Full blown web app with customised browser and tailor made launcher, e.g. in a usb stick / dvd / installer

I have done all of them, and I personally think Jar/Exe is the most balanced solution given your requirement.

Which is sad. If metro app were easily deployable like exe I'd advise that instead.

Community
  • 1
  • 1
Sheepy
  • 17,324
  • 4
  • 45
  • 69
1

Is it possible to somewhat declare a JavaScript File as "local" and thus gaining file-system permissions?

Firefox extensions would have the necessary permissions to access the file system.

Is it possible to use IEs (Or even Chromes/Firefoxes/Whatevers) renderer in Java?

Yes, e.g. with the SWT Browser Widget or JavaFX WebView

the8472
  • 40,999
  • 5
  • 70
  • 122
1

I wonder if this will be enough for you (using HTML5 storage features):

function saveFile(localstorage) {
  localstorage.root.getFile("info.txt", {create: true}, function(theFile) {
    theFile.createWriter(function(theContent) {
      var blob = new Blob(["Lorem Ipsum"], {type: "text/plain"});
      theContent.write(blob);
    });
  });
}

Browsers will ask users for permissions to store files in local system.

Credit where credit is due

blurfus
  • 13,485
  • 8
  • 55
  • 61