Deploy Applet on Apache server - java

I've written a Java applet game that I want to deploy on my Apache server. Code + resources are in a self signed .jar with accompanying HTML doc both in the root dir. When I run it on my local machine everything works fine. When I try to run on the server I get a class not found exception. index.html contains
<applet code=SpaceRaiderz.class
archive=spaceraiderz.jar
width=1024 height=768>
</applet>
The class not found is the class named above. Opened up the .jar and its contents are complete. File permissions set to 755. If I click the index.html on my local machine it loads up and runs perfectly. Ftp the same docs to the server and it doesn't work. Anyone had this problem? I found a similar question to this on here but none of the suggested solutions have worked in this case.

The applet (seen here) works (e.g. showing an asteroids style game featuring a pale green ship that appears suspiciously familiar + sound track) for me in Java 1.7.0_21 on Windows using FF. Refreshing the class cache in the console & then refresh the page might fix the problem for you.
If that fails, there are still more options for testing the applet:
Usually installing another browser (these things are often due to a problem in the particular browser/JRE combo.).
There is also the Appleteer applet testing environment. I can highly recommend it, Since I wrote it.
Go to an internet cafe or the local library to check an applet, if all else fails.

Related

Java Applet Security Issues

I'm having a lot of difficulty getting an applet I made to run in a web browser. Java security keeps blocking it. I have the jar sitting on my desktop and I made a simple html file that embeds the jar using . I'm trying to embed this in html for my website. I don't have any root access to the site at all so I want to avoid using Web Start and Apache Tom Cat stuff because it seems those tutorials assume you're uploading the app itself to the directory of the site itself. I can only embed html here, so I have a jar located in my googledrive.com/host that I'm trying to link.
Here's the code for the tag.
<applet
codebase="https://bb2f18b1cb19b925c50b747c1c65afcc4ad11720.googledrive.com/host/0B34NA0csYJZufm5ZeFFEcUMyQnR5bmw1eVl2M3BOcXItNGxxZTZvaFExNVhXQnY4dzY3QTg"
archive="AsteroidGameApp.jar"
code="asteroidgame.AsteroidGame.class"
width=500
height=500>
</applet>
I don't even know if it would run correctly or not because I can't get past the security. I've read stuff about getting the code signed but I can't find a clear tutorial how to do that.
As reported on the Java related site Starting with Java 7 Update 51, trying to run unsigned Java applications generates error messages and prevents executing the applet.
Follow the instructions about the Oracle proper solution (I my experience I had to get a valid certificate from a trusted root like Verisign and then used this certificate to sign my applet jar) but if you can't do this way, try the suggested workaround in the correspondent section.
Obviously, as stated by the Java site:
It is highly recommended not to run these types of applications. However if you still want to run these apps, run only if you understand the risks and implications.

Opening HTML files in SWT browser from .jar with hyperlinks working

I have a set of help files for my SWT application that I have open in-application using the Browser control. Navigation through the help files is done through hyperlinks of relative pathnames (i.e: <a href="aboutUs.htm">, so only one html file is actually opened by java code, helpHome.htm. I am opening this using String homeURL = this.getClass().getResource("/help/helpHome.htm").toString(); and browser.setURL(homeURL); This works beautifully when I'm just debugging it in Eclipse. Unfortunately, when I move the project into a .jar, the browser gives the standard "can't find this webpage" error. I've tried using the browser.setText(String); function as described in this link, which works for helpHome.htm, but when I click a hyperlink, it brings me to a blank page displaying the relative pathname. Is there a way to convince browser to open an html file from an executable jar using the setURL(String) method? If not, are there any suggested workarounds for me to achieve similar results?
Thanks in advance!!
You have to start an internal Server as explained here on any available port on your application start up and make your html files available as static resources to the server.
Then set the browser.setURL(homeURL). All the subsequent hyperlinks will now point to the server, which knows how to serve the requested resources.
The hyperlinks are resolved to File System Path (Ex. file://C:\workspace....) while you are running or debugging your application in eclipse and things were working fine then. But that is not the case when you run your app from a runnable jar.

How to upload files with java applet?

I know similar questions have been asked but i have searched for hours and as of yet have not come up with a workable solution.
I have a Java applet which will be a "paint" like application. So, I need the user to be able to upload images from their file system. I first tried using a JFileChooser which works great in the eclipse environment. However, when put online i get a "java.security.AccessControlException: access denied" exception.
I was thinking that perhaps within the applet i could call a script (located on my server) which would prompt the user to select a file - but i have no idea how to do this. I am using zymic web hosting, so the only supported scripting language is PHP.
I also tried signing the applet. Since i don't want to spend money on certificates, i self signed the applet. When i tried running it, I got an error stating "The Publisher Cannot Be Verified By A Trusted Source".
Any help would be greatly appreciated. - Thanks:)
A trusted applet can most certainly load files from the local file-system. The "Publisher Cannot Be Verified By A Trusted Source" message that is produced by self-signed applets is onerous & scary (for good reason), but if the user OKs it, it works just fine.
Here is a small demo. of exactly that.
Since the 'Next Generation' Plug-In, even sand-boxed applets can access the local file system. See the last 2 links on the Applet tag info page for further details.
Here is an applet that uses the Next Generation file abilities.
Unsigned applets can not access the file system for security reasons.
There is a tutorial about uploading files using PHP here
Maybe you can work that into your page in order to allow the file to be uploaded and then load it from your web server with the applet.
Do keep in mind the warning at the end of that example under the section "php - file upload: safe practices"

Ways to open a folder/explorer client side from a web page.... Java applet?

I have a need to "pop up" operating system folders from my web app, mostly to locate files in them. My users don’t want to use a conventional web upload/download paradigm. I have 7 or 8 static folders that need to be opened in explorer on a PC or in Finder on a mac. These folders are all network available, but are buried, and for convenience need to be shown on a web page.
There are IE tricks to do this, and I've written a sample flash app that only allows the browser to open, but I know most browsers sandbox this, and keep me from calling these folders. I am aware that some Java libraries deal with the opening of folders, does anyone have any thoughts or samples for this?
The only way I can imagine is to create a Signed Java Applet.
Applets cannot access the filesystem (and a lot of other ressources) if they are not valid signed. Maybe you can also grant the permission by a policyfile.
There ist a tutorial at JavaRanch.
But I am not sure, if this solution will be very helpful, because the JavaPlugin will be removed from a lott of browsers in near future. (I think FireFox already removed it).
I think there is actually NO solution to this problem.
There may be some workarrounds:
Put a Batch-File onto the server, which opens the folder, if executed
Can you create a local service, which handles requests from you webpage and opens the folder.
Create a webapplication, which opens the folder at serverside, and create a webpage, which displays the content in you website.

How to load signed applet from local disc with full permissions?

I have an application where javascript code is accessing java applet methods that write on local disk (just to note - this is not directly possibly, but there is a workaround for it that enables to do so). Applet is self-signed applet, so users have to allow it to run first.
If applet's codebase is set to "http://..." everything works fine, in FF, Chrome and Opera as well. However, I would like to put this applet on local file system. However, if I use codebase "file://..." (I also tried to not use codebase at all and write directly full jar path to archive) it does not work, applet does not load with Warning-Security pop-up that enable user to allow running the applets.
I only tested it in FF (3.6.1.4) so far, Java version is 1.6.0.21.
Are signed applets limited only for HTTP use? Or is there some workaround?
..is there some workaround?
Perhaps using the JNLP API services in an unsigned applet will work better. I have a demo. of the JNLP FileContents object.
For details on using the JNLP services in an embedded applet see the links to the 'next generation plug-in' in the applet information page.
Applets loaded from the local filesystem are allowed to write files only in, or below, the directory containing the applet. So, if the applet is in C:\MyProjects\MyAppletTest it will be able to read and write files in that directory and its subdirectories, but not in C:\MyProjects. You can override this behavior with a policy files as explained in Quick Tour of Controlling Applets

Categories

Resources