MuZo
MuZo

Reputation: 45

Run a java class file from a webpage on the visitor computer?

I coded a Java program to read and modify a file on the computer. The program is based only on 1 class.

At the moment who want to use it has to run it from terminal, I'm looking on how to insert it on a webpage and make it run on the visitor's computer. It would be fine to have a file chooser (the user will want this modification).

I searched on internet and found Java applets, but I read that they aren't downloaded and executed locally so the program won't work.

How to provide a Java class file from a webpage, for use on the computer of the end-user?

Upvotes: 2

Views: 2262

Answers (4)

Andrew Thompson
Andrew Thompson

Reputation: 168835

..it would be fine to have a file chooser ..

In that case, there are basically the two options as I've outlined in comments throughout this question & the answers. I'll collect them together here:

  1. Digitally sign the applet, get the user to accept the digitally signed code when prompted (before the applet is loaded), then offer a JFileChooser to browse to the file.
  2. If the user has a plugin 2 JRE (chase the links in the JWS info. page for more details), it is possible to deliver the applet to the user unprompted, then leverage the JNLP API to produce a file chooser. The user will be prompted before the dialog appears, this time with a more specific warning.

JWS

  • For an example, see my applet based GIF animation tool which uses the JNLP API when the user goes to load image frames or save the animated GIF.
  • That applet is not open source (mostly because of my laziness in not wanting to revisit & tidy the code) but there is a much better example of using the JNLP file services that comes complete with source.

Digital signatures

I don't have any great links about the process of digitally signing code, but note that the 'example of using the JNLP file services' listed above provides one set of signed Jars for 2 different security environments. It also (hopefully obviously) demonstrates how to digitally sign code using Ant (it all happens by invoking the default task in the build.xml).

Upvotes: 1

Brian Agnew
Brian Agnew

Reputation: 272337

If you really want to download a Java program and run it locally, you should check out Java Web Start.

Briefly, it allows the user to download and run a Java program locally on their machine. It does clever stuff like identify if an updated version is available for download, and will run the cached version if that's the current version.

Here's a tutorial.

Upvotes: 3

Applets can modify files locally, if they are signed and the user allows them to.

Read up on signed applets.

Upvotes: 1

user207421
user207421

Reputation: 311008

I read that they aren't downloaded and excuted locally

Whereever you read that, it is 100% incorrect. Applets are downloaded into the browser and executed at the client host.

Upvotes: 0

Related Questions