Link to home
Start Free TrialLog in
Avatar of desiboy1974
desiboy1974

asked on

running a java application rather a browser

can someone tell me how to run a java application straight as a double click from the desktop rather than on a web browser..

basically i have a java chat applet that runs in a browser..so a php page calls the java applet..i want to get rid of the browser and just run it as a application on the client's PC...so when he double clicks on an icon on the desktop it will run the java applet..the java files all sit on the server though..i have the java runtime running on every clients PC..also a paremeter gets passed to the browser currently which is the clients ID..so i'd like to pass that too when running it as a applications..thanks
Avatar of suprapto45
suprapto45
Flag of Singapore image

Mmm....

On my opinion is that you need to create either .bat file that will execute your applet class or you need to create .exe file for your applet. Normally, .bat file would be sufficient but assuming that your client has JVM installed.

let me try to find the URL to help you.

Regards
Dave
Avatar of aozarov
aozarov

You can invoke the appletviewer programatically by calling the main method of java sun.applet.Main
e.g java sun.applet.Main http://www.vipan.com/htdocs/swing.html
Hi,

How about these URL..

http://www.builderau.com.au/askexperts/java/0,39024791,20283101,00.htm

JAR File
http://java.sun.com/docs/books/tutorial/jar/basics/index.html

For example, you have 12 classes for your applet. You need to bundle them into one .jar file and create .bat to execute the main class.

I hope that helps.

Regards
Dave
Hi aozarov,

nice to meet you :).

Regards
Dave
Avatar of desiboy1974

ASKER

i have all the files in a jar..

currently i call it in a browser

<body>
<applet archive='peoplechat.jar,classes12.jar' code='ClientApplet.class' name='bdon' alt='asd' width=700 height=700 MAYSCRIPT>
<PARAM NAME='custService' VALUE=\"$custService\">
</applet>
</body>

This is what i want to convert to a application..if i use a .bat file ..how will it reference the jar files that run on the server when the .bat file runs on  the client?
Hi, suprapto45
I am going to sleep now. so I will leave the place for you ;-)
ASKER CERTIFIED SOLUTION
Avatar of sudhakar_koundinya
sudhakar_koundinya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mick Barry
First you'll need to convert your applet to an application.
Then jar up the classes as an executable jar.
http://java.sun.com/docs/books/tutorial/jar/basics/run.html
Hey desiboy1974, you can run any jar by double clicking,
both on MSWindows as on LINUX.
For MSWindows: as soon as you install JAVA (SUN) the relation is made to execute .jar (see registry)
with javaw (no console window).

If this is not the case on your machine, execute the next file "jar.reg" :
//////////////////////////////start
REGEDIT4

[HKEY_CLASSES_ROOT\.jar]
@="jarfile"

[HKEY_CLASSES_ROOT\jarfile]
@="Executable Jar File"

[HKEY_CLASSES_ROOT\jarfile\shell]

[HKEY_CLASSES_ROOT\jarfile\shell\open]

[HKEY_CLASSES_ROOT\jarfile\shell\open\command]
@="\"C:\\Program Files\\Java\\j2re1.4.2_04\\bin\\javaw.exe\" -jar \"%1\" %*"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.jar]
@="jarfile"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile]
@="Executable Jar File"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile\shell]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile\shell\open]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile\shell\open\command]
@="\"C:\\Program Files\\Java\\j2re1.4.2_04\\bin\\javaw.exe\" -jar \"%1\" %*"
//////////////////////////end
You should replace the "j2re1.4.2_04" by the version of JAVA you are running.

Next: every .jar must contain a manifest file to indicate the starting class;
example manifest: "Manifest.mf"
//////////////////start
Manifest-Version: 1.0
Created-By: 1.4.2_03 (Sun Microsystems Inc.)
Main-Class: MyMainClass

//////////////////end
Notes:
1) the version info in the manifest is not significant (yet),
2) replace "MyMainClass" by the name of yours,
3) line 4 is indeed empty, don't delete it!
4) the structure of the .jar file is important:
    in the 'top' directory your (main) classes should be AND a directory named "Meta-inf";
    the manifest file should be in that last directory.

The 'jar' command and almost all IDE's will create a .jar file to these specifications.

Success!

;JOOP!
P.S.: an applet must be called from a 'main' class as if that were the browser.
You could also modify the Applet into a main class from:

//////////////////start
public class MyFormerApplet
{
      public static void main(String[] commandline)
      {
................
      }
}
//////////////////////end

;JOOP!
after convertying the applet to an application and jarring up the classes

how do i reference the executable from the client PC when the files reside on the server?
Web Starts best for that, see the details posted earlier by sudhakar_koundinya.
Sorry for the delay but I think that everything is covered already.

So good luck

regards
Dave
You can try just adding the applet to a frame. If you can let us know where it is, we may be able to try this
If you don't mind to keep it as an Applet (and you don't want to use the browser) then why not to use the appletviwer.
And as I suggested you can do that by either embeding it inside your code (by invoking java sun.applet.Main or using sun.applet.AppletViewer directly [see tools.jar for those classes])
or launching the appletviwer from a script (as suprapto45 suggested). Doing so will require no code change.
And as for where to put 'peoplechat.jar' and 'classes12.jar' just put them in the same folder as ClientApplet.class