Search code examples
javaapplet

Can you run a java executable on a webpage?


I know similar questions to this have been asked before but I can't quite seem to find an answer. I'm attempting to run a java executable file which has other file dependencies on my web page and am not quite sure how to do it with applets. I don't care about any security issues, as for the moment, it is just for private testing.


Solution

  • Well, a webpage is really a bunch of text, and text doesn't really "run" anything, so in a sense no.

    Now, a web page can contain the "text" of an executable program, and many web browsers read that "executable program" part of the text and run it. So in a sense, web pages can contain executables that run when they are viewed.

    Finally, Java's mechanism for inclusion into a web page is not just one thing. In the early days, it's inclusion into a web page included "java applets", which after a period of adoption, eventually became under-used, and finally saw most web browsers drop support in an effort to reduce the ways one can delivery web page malware.

    A second web page delivery of Java has been introduced, JNLP, or "Java Web Start". In this approach, following a web page link would cause a Java program to be downloaded to the machine, and the program would run. This was an improvement in the security compared to applets, but not enough of a security improvement to satisfy all people. JNLP, again primarily due to the low adation / bad press ratio, was dropped.

    This means that the only remaining options for Java related to web pages are:

    1. Use the link to download a full fledged Java program (perhaps an installer)
    2. Build the Java application on the server side, so the Java code doesn't need to ever run in the web page (ok, actually the web browser), but only inputs and outputs web pages.

    Most web applications have been doing #2 for quite some time now. Most pre-web applications have been doing #1 for even longer.

    Note that the installed program doesn't need to be web unaware, it can still connect to back end Java Web Services, which use web technology, but are not "Java code running in a web browser".

    I hope this helps, and if you're a fan of Java, don't think that it's lack of "run in a web browser" makes it a bad choice, no programming language besides JavaScript has any kind of ability to "run in a web browser" these days.