[java] Need some help with Java
I want to write an applet in Java that will detect if the Microsoft VM and/or the Sun VM are installed, and also if Java Web Start is available.
After doing this, I need it to pass some results that can be accessed via javascript.
Any help will be appreciated.
Thanks.
I'm not a Java programmer, but am I not right in saying that the Java applet won't run at all if you don't have any VM?
You are correct. I messed around with Java a while back. To run a java executable (.jar), a VM needs to be installed. Windows does not know how to run them alone.
Quote:Original post by ukdeveloperExactly; so if no result is returned from the applet, there is no VM installed. I don't know if a Java applet can tell which VM it's running on, though [sad]
I'm not a Java programmer, but am I not right in saying that the Java applet won't run at all if you don't have any VM?
Oops... ok, hopefully, this can get moved by a moderator to the appropriate forum.
On the other hand, if no VM is installed, this is where javascript comes in. Since javascript doesn't receive any results from the applet, because it doesn't run, then we can easily display that no VM is installed.
On the other hand, if no VM is installed, this is where javascript comes in. Since javascript doesn't receive any results from the applet, because it doesn't run, then we can easily display that no VM is installed.
No probs, happens all the time [smile]
I sent them a quick message asking it to be moved to the Java forum, since you will probably get better help there. I wish I knew more about Java so I could help you myself [grin]
I sent them a quick message asking it to be moved to the Java forum, since you will probably get better help there. I wish I knew more about Java so I could help you myself [grin]
Quote:Original post by liquidAir
I want to write an applet in Java that will detect if the Microsoft VM and/or the Sun VM are installed, and also if Java Web Start is available.
After doing this, I need it to pass some results that can be accessed via javascript.
Any help will be appreciated.
Reading your posts and inferring your level of knowledge of java I strongly suggest you tell us what you're trying to do, rather than how you're wanting to do it - there are several orthogonal ways to achieve what you asked, but some will be completely useless depending upon what you're trying to do.
e.g.
1. install java?
a. Use browser-detection to find if the user is running MSIE.
b. If so, use MSIE's built-in stuff to find out if they have the java plugin, and webstart, and what versions of each
c. If not, run the ActiveX control that installs java webstart and runs your webstart app
d. If not MSIE, check if windows
e. If so, run the ActiveX control anyway - it won't downlaod if you already have java
f. If not windows, insert a link to Sun's undocumented auto-install-java page which they don't want to tell anyone about because their marketing dept are all morons
2. just guarantee your applet runs?
a. All versions of windows already have java.
b. ...but linux probably does not
c. ...and you can remove it from some web browsers
d. If someone's removed it, they probably don't want it (!), so don't you dare give it to them; have to display a "please install java, go here..."
e. If they don't have it in the first place, on linux you have little choice other than to detect the browser then provide the link to that browser's "install java plugin" website
3. ....run code optimize for differnet JVM's
a. Gets tricky, depending upon what you want to achieve...
redmilamber
Alright, so after combining intensive Googling, trial and error, and bad coding practices *g*, I came up with this...
<html><head><title>Detect Java VM and Java Web Start</title></head><style type="text/css">BODY { font-family: Arial, sans-serif }TH { text-align: left }</style><script language="javascript" type="text/javascript">var browserInfo = navigator.userAgent;// variable to check if Java Web Start is installedvar jwsInstalled = 0;// Microsoft VM?var msvmInstalled = 0;// Sun VM?var sunvmInstalled = 0;// variable to check if client is MSIEisIE = "false";// If we are using if(navigator.mimeTypes && navigator.mimeTypes.length){ var flag = navigator.mimeTypes['application/x-java-jnlp-file']; if(flag) { jwsInstalled = 1; }}else{ isIE = "true";}// We are using another browser, not MSIE// Opera, Mozilla, Firefox, etc...if(isIE == "false"){ javaEnabled = window.navigator.javaEnabled(); if(javaEnabled == "true") { javaVendor = java.lang.System.getProperty("java.vendor"); if(javaVendor.indexOf("Sun ") != -1 || javaVendor.IndexOf("sun ") != -1) { sunvmInstalled = 1; } }}// Our client is using MSIEelse{ // check if ActiveX objects can be created try { // Create Sun Java plugin ActiveX object var pluginObject = new ActiveXObject("JavaPlugin"); // Create Java Web Start ActiveX object var jwsObject = new ActiveXObject("JavaWebStart.isInstalled"); } // they cannot be created catch(e) { // Sun Java plugin and Java Web Start not installed sunvmInstalled = 0; jwsInstalled = 0; } // Sun Java VM object successfully created? if(pluginObject) { // Yep! We have the Sun Java VM plugin installed sunvmInstalled = 1; } // Java Web Start object successfully created? if(jwsObject) { // Yep! We have Java Web Start installed jwsInstalled = 1; } // Minimal Code Hack // All versions of Windows up to 2000 have Microsoft VM installed by default // No official Microsoft VM is distributed for Windows XP and above // Users of Windows XP and above will be required to install the Sun Virtual Machine var UserAgent = navigator.userAgent; if(UserAgent.indexOf("Windows 95") != -1 || UserAgent.indexOf("Windows 98") != -1 || UserAgent.indexOf("Windows NT 5.0") != -1) { msvmInstalled = 1; }}</script><body><table cellspacing="0" cellpadding="5" width="400"><tr><th>Java Version</th> <th>Installed</th></tr><tr><td>Microsoft Java VM</td> <td><script language="javascript" type="text/javascript">if(msvmInstalled == 1) { document.write("yes"); } else { document.write("no"); }</script></td></tr><br><tr><td>Sun Java VM</td> <td><script language="javascript" type="text/javascript">if(sunvmInstalled == 1) { document.write("yes"); } else { document.write("no"); }</script></td></tr><br><tr><td>Java Web Start</td> <td><script language="javascript" type="text/javascript">if(jwsInstalled == 1) { document.write("yes"); } else { document.write("no"); }</script></td></tr><br></table><br></body><br></html><br></pre><br><br><!--EDIT--><span class=editedby><!--/EDIT-->[Edited by - liquidAir on May 30, 2005 1:31:13 PM]<!--EDIT--></span><!--/EDIT-->
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement