views:

495

answers:

5

I have a Java applet that is meant to run only on Windows. (It uses a 3rd party COM object; it is not cross-platform.)

Is there a way to run a Java applet as a stand-alone application on Windows?

A: 

If by "applet" you mean a stand-alone command shell Java program, a simple batch file should suffice:

@rem MyApp.bat
@echo off
set JVM={{path where java.exe is located}}
set FLAGS={{optional JVM flags}}
set JARFILE={{location of your jarfile}}
%JVM%\java %FLAGS% -cp %JARFILE% {{Package}}.{{Class}} {{args...}}

Replace the items enclosed in braces {{...}} with settings appopriate for your application. If everything is defined correctly, double-clicking the batchfile name in a file explorer window will execute your Java class.

Loadmaster
Why would applet mean a stand-alone command shell Java program?
Hemal Pandya
Apologies, although in my experience, some people have some confusion over the term "applet".
Loadmaster
+4  A: 

Although you can certainly run it, there are subtle differences between how Java runs as an application vs. how it runs as an applet. One starts with an init method, the other starts with a main method, and the threading and event queue relationship to startup are a bit different.

Here is some documentation from Sun on how to do it. If you are using JApplet things change slightly, but the idea is the same.

Yishai
Thanks for your answer. I ended up going with the "applet stub" as talked about in the link you provided. This allowed me to keep my existing applet code, add a new class to hoist the applet from a main(String[]) method, and export my code as a Runnable Jar File (In Eclipse, File->Export->Runnable Jar File). This works! I've marked yours as the answer.
Judah Himango
+1  A: 

Java applets usually don't have a main method. They rely on the webbrowser to be launched.

It is possible though that you create a new class which have a main method and simple call the init() and start() method of the applet.

You may take a look at this to understand better the life cycle of the applets.

OscarRyz
+1  A: 

I suppose the appletviewer could be an option. It is a utility included in the JDK.

McDowell
+1  A: 

The JDK has an appletviewer applet launcher. It is not available in the JRE and its behaviour may be slightly different from the PlugIn.

Also applets can be run from WebStart if an appropriate JNLP file is provided.

Tom Hawtin - tackline