Applet on wordpress blog - java

I just finished making a Java applet and it works on my localhost server, however, I want to upload it to my blog on wordpress. How should I go about doing that?
I've never done it before, it's my first time, so help is greatly appreciated. Do I upload my .class files to wordpress, or do I upload them somewhere else and link them in my HTML file? If I do upload them to a different server, I'm not sure how to link to them. If anyone knows of a tutorial or is willing to tell me how to go about doing this it would be much appreciated.

I'm not sure you can upload applets to that site, or include applet elements, but if you can run scripts and hot-link to it elsewhere, it should not be a problem. The script to use is the Deployment Toolkit Script.
Do I upload my .class files to wordpress, ..
Don't upload loose class files. Very soon all applet code will need to be digitally signed in order to not be automatically rejected by the Java Virtual Machine. To be digitally signed, code must be in a Jar file.
..or do I upload them somewhere else and link them in my HTML file?
If you need to go with 'somewhere else', it should just be a matter of specifying the codebase to point to the site. Here is the example from the Using Applet Tag Attributes of that document linked above.
<script src="https://www.java.com/js/deployJava.js"></script>
<script>
var attributes = {codebase:'http://sample-url/Java2D',
code:'java2d.Java2DemoApplet',
archive:'Java2Demo.jar',
width:710, height:540} ;
var parameters = {fontSize:16, permissions:'sandbox'} ;
var version = '1.6' ;
deployJava.runApplet(attributes, parameters, version);
</script>
Note that I altered it slightly in the code attribute, because it irritates me to see Oracle itself perpetuating a myth that adding the file extension is a good idea. The code attribute should be the Fully Qualified Name of a class, rather than the file name.
If anyone knows of a tutorial..
I know a lot of good resources about applets, and I included links to them in the Applet tag info. page here at SO.
All the best. The (robust) deployment of a simple applet can be more tricky than the development of it - you have a steep learning curve ahead.

Related

Wordpress doesn't accept web.xml mapping? Or Java build classes?

I am a beginner and self learning web development for my personal interest, and I have a general question.
I developed a Dynamic Web application in eclipse which uses index.php (or .html ; I can choose) to make a call to javascript file, the JS file calls a java servlet for some optimization and internal calculations through AJAX call, and returns back data to JS and later to the HTML form on index.php. All the paths and mappings are done on web.xml file, and everything works perfectly! The project involves some external google libraries as well, which I have included in eclipse through Build Path.
Then I installed Wordpress locally through Xampp and copied all these files (including all the java classes and external JARs) keeping the folder structure same. Here, index.php does make the call to javascript file, but for AJAX call to java it shows me network error 404. So I have 2 questions:
Does the Wordpress doesn't accept mapping through web.xml? Should I only use absolute paths? I am avoiding absolute paths since I want flexibility in moving files around and I don't know how it will work online when I upload my project somewhere.
Or is the Wordpress/ Xampp not building/ compiling Java classes and external JARs somehow like it is done in Eclipse? I have no idea how this works! I did copy all the updated class files and stuff to the wordpress folders.
Please let me know how to proceed from here, or any suggestions in things I need to learn! I am keen to use Wordpress since it will save me lot of time in writing all the page codes for my website but the java file is also integral to it since it does lot of backend work. I saw lot of comments online that wordpress and java don't go together since it being a PHP based (I actually learned PHP due to this), but it works in eclipse using these 2 languages, so I am hopeful!! So any guidance will be really appreciated!
Thank you! :D
Anang

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.

ClassNotFoundException running simple applets

I wrote http://pastebin.com/EwShF3YS for school; It's a simple java applet with a GUI pair of eyes that watches the cursor as it moves. It runs well in a compiler (NetBeans 7.4) , but for the life of me I'm having difficulty understanding why it doesn't run in a browser. I'm getting ClassNotFound exceptions. All the reading I've been doing suggests that a .class file isn't required because it's an applet, the browser should generate one at runtime. And if a class is required, how come NetBeans can run it without one?
The HTML file is stored in the same directory as the .java - and it's real simple:
<html>
<head>
<title>WatchMe</title>
</head>
<body>
<applet code="WatchMe.class" width="300" height="200">
</applet>
</body>
</html>
I've tried a variety of different things, different browsers, setting classpath; opening it on different computers. The result is always the same, ClassNotFound exception. The internet research I've been doing yields mostly unproductive answers, such as one person who completely reloaded his PC. I've noticed that if I fully qualify the path to WatchMe.class I get a hang/blank browser page. I'm completely out of ideas, so any suggestions or advice is welcome.
You need to have the compiled WatchMe.class in the same directory as HTML File. Having the .java file is not enough and no the browser will not compile anything for you. It will just run the .class file using the JRE.
All the reading I've been doing suggests that a .class file isn't required because it's an applet, the browser should generate one at runtime.
This is incorrect. You must provide either a ".class" file, or JAR files containing ".class" files for the browser to fetch.
A web browser's Java plugin is not capable of compiling Java code. If you've found a resource that tells you otherwise, it is WRONG. (I'd be interested to see concrete examples of this misinformation! Can you post the URLs?)
It is possible that your confusion arises from reading material on Javascript and thinking that it applies to Java. Don't!! They are very different languages ... and material on one does not apply to the other.
OK so why is your example not working?
It is hard to say, but the most likely reasons are:
you've used the wrong name or path in the "code" attribute,
you need a "codebase" attribute to allow the browser to map the ".class" name to the correct URL for downloading it,
your code depends on other classes (that are not in the browser plugin's class library), or
it is a bytecode version issue; i.e. you have compiled your applet with a later version of Java than is supported by the browser.
Try looking in the browser's Java console for the complete error message and stacktrace for the exception.
Try looking at the server-side HTTP logs to see what files that the client is attempting to fetch ... and what the server's response is.

Loading a .jar onto the webpage without the user being able to access it

Kind of hard to explain in one line but my problem is essentially like this:
I made a java applet that I want to run on a web page that I packaged into a .jar file. I'm able to get the applet working fine using the <applet> tag but the problem is, if the user views the page source, they will see:
<applet archive="directory/program.jar">
Assuming .jar files can be easily opened and all the class files decompiled, all the user would have to do is go to www.url.com/directory/program.jar to download my .jar and they would have all my source code :(
So I'm wondering if there is either a way to protect my code/jar from being decompiled (other than obfuscation) or to use some kind of server-side script to feed the contents of the .jar directly to the browser from a server-side location not publically visible.
Any help is appreciated.
This is fundamentally impossible.
Java applets run the client.
Anything that runs on the client can be disassembled and modified by a sufficiently advanced user.
You should move your sensitive logic to the server and invoke it using HTTP requests ( and remember that the user can use Fiddler).
While you're at it, you should probably replace your applet with HTML and Javascript.
Other than obfuscation or encryption, no--one way or the other, the browser will have access to the jar.
You might be able to create an applet that loads more functionality at runtime.
There is no effective way to block access to the source code of any page; for the page to be readable by browsers and search engines, the source code has to be accessible, and therefore can be viewed and/or copied. That's just how the web works. HTML is sent as a text document and interpreted client-side.
Disabling the right-click is little more than an annoyance, and it works sporadically in alternative browsers. Even if you succeed, the View Source option in the menu is always present. The viewer could also use a download tool such as Wget, or even get the page from the Google cache without visiting your site at all.
Edit: Oops! I misunderstood your question. You should follow #SLaks advice and "move your sensitive logic to the server and invoke ot using HTTP requests ( and remember that the user can use Fiddler)."
While quantum mechanics do rule the universe, they have less of a grip on your code than you might suspect. You cannot both deploy code to the client browser and not deploy code to the client browser. You have the option of doing one or the other.
You can prevent direct browsing to your .jar file by locating it beneath the WEB-INF directory in your WAR file. This will also prevent <applet archive="directory/program.jar"> from working.
Once the jar is beneath the WEB-INF directory you will need something to feed the resource to the client browser; the Spring resources servlet is good for this (If you are using Java and Spring). I feel confident that other such tools exist. With the Sprint resours servlet, your would deploy your applet with something like this: <applet archive="resource/program.jar".
If you write your own resource distributor, you can add security to make it harder to get the jar file; perhaps add a header to your requests like IRGud: <user_id here> and fail any request that does not have that header (or acceptable contents in the header).

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"

Categories

Resources