Migration of Java Applets to Java WebStart and GWT - java

I have an application that uses a "signed" applet which is packaged inside a jar that does the following things:
Checks whether the file exists in the directory while uploading a file and opens a form for details.
An applet is included in JSP and checks the file exists in local system by getting storage path while uploading.
Checks whether the applet is active and downloads the file to local system.
Add files to application that will be stored as local copy in file system.
As the support for applets is getting removed, I would want to migrate from applets. I would like to know is Java Web Start the best option for replacing applets in terms of "security, trusted code" and signature. Are there any other technologies that comes useful for my application in the above areas?
Also found that
Migrate Java Applet to what/where?
Replace Applet in downloading and executing a file
Any suggestions on this?

Related

Run applet java in html

I have an applet java displaying images from folder ,i cant run this applet using html i have this error :
The error you are getting is because your applet is trying to read a file from a directory in the local system where it is getting downloaded. This is a standard security feature. This of this way, you go to a website which downloads an applet and read a file or executes an .exe in your local system. Naturally this should not be allowed for an applet / javascript or code served from a server.
You need to create a signed applet. Please go through the following link to accomplish your need :
http://www.developer.com/java/other/article.php/3303561/Creating-a-Trusted-Applet-with-Local-File-System-Access-Rights.htm

Moving web application (Java/JSP) to a web server

I have developed an application with Netbeans (Using Java, JSP and JQuery) in Windows environment. Now I am ready to transfer the application to a web host so that the application can be available on the Web and I am told that the application would have to be moved to a linux environment (hosting service already bought). Here are my concerns:
How to convert my code to Linux? Is there an automatic tool for this?
How to deploy my application to the server online (what do I need to copy and to what directory on the web?)
My application writes to a directory on c:drive on my laptop, what should I do to make the application write to correct directory a designated directory on the web server?
I have read here and there online but just haven't got specific solutions to this.
How to convert my code to Linux? Is there an automatic tool for this?
One of the Java key features is portability, so as far as you haven't used any OS-specific code like running a program using CMD or similar or a library that is OS-dependant (which is rare in these times but there are some yet), then you don't have anything to do.
How to deploy my application to the server online (what do I need to copy and to what directory on the web?)
You need to generate a WAR file. This file will zip all your web pages (JSPs) and web resources (js, css, image files) along with the Java binaries (*.class) and libraries (that must be on WEB-INF/lib folder).
Since you're working with NetBeans, here's a Q/A to generate the war file: How can I create a war file of my project in NetBeans?
This war file must be placed in the deploy folder of your web application server. Usually, the hosting provides you the tools (generally a link on the web with user and password) to administrate the host, based on this you should ask (or find it by yourself) the option to upload the war file.
My application writes to a directory on c:drive on my laptop, what should I do to make the application write to correct directory a designated directory on the web server?
You need to configure this path as a constant in your application, or even better, configure it in a properties file (or somewhere else) in order to be read and use it by your application easily. Remember that the path should be generic to be supported in almost every OS. For example, if you use a path with name
C:\some\path\for\files
Its generic form will be:
/some/path/for/files
Since you're going to work on Linux, make sure the user who executes the Tomcat (or the web application server you will use on production) have enough permissions to write on that folder. This can be easily done (and somebody here can fix this please) using the chown command:
#> chown -R user /some/path/for/files
Here's another Q/A to manage files and path on Java web applications: How to provide relative path in File class to upload any file?
OK, first a few thoughts:
Convert code to Linux. Once you have your ear of war file, you can just deploy them. It's best if you use UTF8 enconding in your files, specially if you use special characters, but that would be an issue you could test out when you deploy, could also be dependant on the Linux configuration. Having that said, Java is portable and you only have to be sure that the archive you create is compatible with the AppServer that's installed on the Linux hosting. You should get all the information you need about the deployment environment from the hosting site / company.
Deployment will depend from site to site, they should give you all instructions.
Here you might have a problem. I would say that the easiest way is to just map the directory in a properties file and customize it on every machine you use it. That's the easy part so far. However, you should check if your site will give you access to a directory, and be aware of space limitations and cleanup of the files. If you get, let's say, 100MB and you use 10MB a day, you might end up with trouble after 10 days...

Packaging a Java app. w/DB to run on client machine

I made a simple java desktop application using embedded database. I wanted to package all files into a single file like exe so that client can click just on one file and use the application. I made the jar file and its working fine on my system when double clicking. I wanted to package the DB file along with jar because the data is shown only when the DB file is in the same folder of jar file.
I came across several tools like launch4j, install4j etc. but I didn't find where to include the DB file along with the package.
It sounds like you want an installer of some description, such as IzPack. This would allow you to package both jar and database together, and install them on a client system.
A good way to deploy rich client (e.g. Swing/AWT) apps. that require some set-up (as in, installing a DB) is by using Java Web Start.
JWS offers the ExtensionInstallerService which..
..is used by an extension installer to communicate with the JNLP Client. It provides the following type of functionality:
Access to prefered installation location, and other information about the JNLP Client
Manipulation of the JNLP Client's download screen
Methods for updating the JNLP Client with the installed code
Here is a demo. of the EIS (with code, build file etc.).

Java IO outside jar

I'm working on a browser based applet game, and I intend to store the top ten scores in a text file in the directory with the JAR file. How would I read and write to a text file if it's outside the JAR file?
As far as I know the only way to do this is via the JNLP persistence service
A signed applet (jar, JNLP) has the same disk IO permissions as the user running the applet.
Otherwise, javax.jnlp.PersistenceService is your best bet.

How do I load and display a remote jar applet in my applet?

I would like to load remote applets into my own applet.
For example, lets say I want my applet to download and display a game from this site within my java applet:
http://www.java4k.com/index.php?action=home
How do I do that?
You can use a signed applet to access the local file system and bypass the same-origin policy.
The LWJGL java library has developed an "applet loader" you can modify and reuse.
http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/applet
Here is an example use in the wild: http://www.paulscode.com/demos/SoundSystem/09AUG2009/Helicopter.html
Basically, the applet_loader downloads a bunch of file, write them on the disk, add them to the classpath, instantiate the target applet, and then proxies Java methods call on it to the target applet (Applet.start, Applet.stop, etc..).

Categories