I'm developing a java application that needs to do some calculations and needs to be available online.
I develop in Java since 2005 but never had to put online anything, I always used RMI.
I studied how to create applets and successfully converted my desktop application into an applet (applied applet lifecycle, converted JFrame into JApplet, etc.)
What I noticed is that performance is really slowed down, so I tried alternative ways. I read about Java Web Start, and started thinking about it.
Found this article: http://docs.oracle.com/javase/tutorial/deployment/deploymentInDepth/runAppletFunction.html and following it I did the following things (writing all down for future readers reference):
- made a jar of my application and signed it (obviously names are altered)
wrote the following JNLP:
<?xml version="1.0" encoding="UTF-8"?> <jnlp href="appJNLP.jnlp"> <information> <title>Software title</title> <vendor>Society name</vendor> <offline-allowed /> </information> <resources> <j2se version ="1.6+" initial-heap-size="256m" max-heap-size="1024m" href="http://java.sun.com/products/autodl/j2se" /> <jar href="app.jar" main="true" /> <jar href="mysql-connector-java-5.1.20-bin.jar"/> <jar href="poi-3.8-20120326.jar"/> <jar href="forms-1.3.0.jar"/> </resources> <applet-desc name="Name" main-class="mainClass" width="1024" height="700"/> </jnlp>
wrote the following HTML page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Titolo</title> </head> <body> <script src="http://www.java.com/js/deployJava.js"></script> <script> var attributes = {code:'mainClass.class', archive:'app.jar,mysql-connector-java-5.1.20-bin.jar,poi-3.8-20120326.jar,forms-1.3.0.jar', width:1024, height:700} ; var parameters = {jnlp_href:'appJNLP.jnlp'} ; var version = '1.6' ; deployJava.runApplet(attributes, parameters, version); </script> <noscript>This page requires JavaScript.</noscript> </body> </html>
put the following files structure in my Tomcat webapp folder:
webapps\app app.jar appJNLP.jnlp page.html mysql-connector-java-5.1.20-bin.jar poi-3.8-20120326.jar forms-1.3.0.jar
As you can see I chose the mixed deployment way (stated on the link posted before this approach enables applet to run on the old and next generation Java Plug-in software). I think I did everything fine. The applet loads in the web page but it's very slow... I added memory parameters in the jnlp section following this response: How can I start an Java applet with more memory? (initial-heap-size="256m" max-heap-size="1024m") but they seem to get ignored. I tried also putting false values, like initial-heap-size="5000m" on my 2gb RAM machine, but the applet still loads and still is slow. The console shows this after a rundown of the jnlp file, but the applet still runs:
Match: selecting maxHeap: 8388608000
Match: selecting InitHeap: 5242880000
Match: digesting vmargs: null
Match: digested vmargs: [JVMParameters: isSecure: true, args: ]
Match: JVM args after accumulation: [JVMParameters: isSecure: true, args: ]
Match: digest LaunchDesc: http://localhost:8090/TestServer/gestioneoneri.jnlp
Match: digest properties: []
Match: JVM args: [JVMParameters: isSecure: true, args: ]
Match: endTraversal ..
security: --- parseCommandLine converted : -Xms5000m
into:
[-Xms5000m]
Match: JVM args final: -Xmx8000m -Xms5000m
Shouldn't it throw an exception??
Now my questions are:
- how can I be certain that the code is getting executed in JNLP environment and not in the applet environment? I see no Java Web Start logo. Is it normal?
- how can I increase initial and max memory size to more human values?
- I need this software to be embedded in the web page. Since I don't know if what I'm using is an applet or a java web start application, how can I improve my users experience? I'm talking about extending JApplet or JFrame for example.. In the case I cannot increase memory how should I convert my applet into a jws app?
I'm open to suggestions. Thank you for your time!
Andrea