Can an embedded Java Applet be hosted on Git-Pages? - java

I want to embed a java applet (stored in a git repository) in the accompanying github-pages page. Is this possible?

Yes.
Although GitHub pages can be generated through a simple markdown interface, any files in your branch will be served as part of your gh-pages-site.
This means you can host client side scripts like Java-Applets or JS on your GitHub Pages site.
To host a java applet:
Create a jar file for your Applet.
Place the .jar file into the root of your gh-pages branch.
Embed the applet in one of your html pages using your prefered method like this, or maybe this:
*Assuming foo.jar and Bar.class are your file and applet-class*
<embed
id="SomeName"
type="application/x-java-applet;version=1.6"
width="999" height="999"
archive="foo.jar"
code="Bar.class"
pluginspage="http://java.com/download/"
myParam="YourParams" />
Commit/Push the changes and wait (sometimes gh-pages are not updated immediately).

Related

How to make Java Applet load/charge xml in the same folder at runtime

Hello I'm working on a web application (runs on IE) which is mixed with Applet, XML and DLL files(since app needs to access machine's scanner). The case is somewhat special: When Applet is loaded into browser, it needs to load simultaneously a scannberLib.jar and 2 XML files so as to perform scanning analysis.
There is no problem loading ScannerLib.jar and calling Applet, but 2 XML files are never correctly loaded. Specially, we tried the supplied sample application (jar file) and proved scanning analysis only works when 2 XML files are in the same folder of sampleApplication.jar.
The application structure is shown as follows:
end user----> Web app page ----> page loads Applet (jars & lib)-->Applet calls init method in scannerLib.jar---->Scanner lib read related DLL files & DLL file (we have no control) read XML file to do scanner analysis...)
My question is how to make java applet "BE AWARE" and"load/charge" other files(xml) at runtime?
Thank you in advance!

Applet referencing to localhost gets blocked if html is on shared drive

I have an html file with applet code like
<applet code="myapplet.class" archive="http://localhost:8080/myapplets.jar"width="350" height="350"></applet>
The applet loads fine if the html file is local to the machine but if that html file is on shared drive (windows) and if html file opened ( so that the address in the address bar is
\X.X.X.X\testhtml\myapplethost.html ) then
While applet is trying to load , this exception is thrown
java.lang.SecurityException: Permission denied: http://localhost:8080/myapplets.jar
I have added both the
http://localhost:8080 and file:\\X.X.X.X\testhtml
to the exception list. Have lowered the security to the lowest possible (i.e Medium) in java control panel (JRE 1.7 upate 67) but this applet keeps getting blocked. Is there any settign that can help here to allow the access to applet from the shared location? Thanks
The archive parameter of the applet can only reference archives (e.g. jar files) from the same source the applet was started. Here is the quote from the official documentation:
For security reasons, the applet's class loader can read only from the same codebase from which the applet was started. This means that archives in archiveList must be in the same directory as, or in a subdirectory of, the codebase.
If you load the HTML page from a shared drive, the archive attribute of the applet tag in the HTML file should not point to http://localhost:8080/myapplets.jar. Most likely this is just a mistake (you forgot to change it or you forgot to use relative URL).
Just change the archive attribute to a relative URL and it will work. Something like this:
<applet code="myapplet.class" archive="myapplets.jar" width="350" height="350">
</applet>
Absoulte URLs are always a bad idea and this is especially true for applet archives.
Used shared drive path (like Z: instead of \server ) and it works.

JApplet works in applet viewer, not in HTML page

This topic has been covered in one form or another but none of the other threads have been able to help. My issue is very similar to this post, I am making a JUNG graph with added functionality, but none of the solutions helped:
JApplet fails to run in HTML page
I had a Java application that I converted to a JApplet. The JApplet works fine in the applet viewer in Eclipse but will not work when I try to open it in a webpage (I have tried IE, FireFox, and Chrome). I have my HTML page and archive folder both in the same directory. When I load the HTML page it just brings up nothing.
Here is my html code:
<html>
<title>Applet</title>
<head>
</head>
<body>
<applet code="prerna.blueprint.main.BPTester.class"
archive="applet1.jar"
width="800" height="800">
</applet>
</body>
</html>
When I try to have code="BPTester.class" it gives java.lang.ClassNotFoundException: BPTester.class but when I use code="prerna.blueprint.main.BPTester.class" it gives me no errors just nothing happens. (prerna/blueprint/main/BPTester.class is the file path in my src folder). I exported my Java project as a runnable jar file, is this correct? I created a simple JApplet that worked fine when I did all the same steps but it won't work for BPTester.class.
If I need to post my BPTester.class code I can.
I don't understand why I can't view the JApplet in a webpage, any help is greatly appreciated.
What ended up working for me was adding every single jar I used in the japplet to the HTML archive tag then had to sign every jar. I then had an issue with accessing my database within the applet1.jar so I just put an absolute path for its location.
java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
The applet needs to be digitally signed (by you) and trusted (by the end user, when prompted) before it can obtain such information. Given this applet is being deployed using a traditional applet element (i.e. not using web start), all jars need to be signed.
You need to sign every jar. You can sign all the jars with the jarsigner utility. Example:
jarsigner.exe "nameofthejar.jar" "alias"
Remove .class from the end. You either use a file path with slashes and .class at the end or you only use periods and no .class at the end.
Try turning on tracing in the java control panel. It will then produce a log file in the following path that may help: %USERPROFILE%\AppData\LocalLow\sun\java\Deployment\log

Access a file from a web service

I am using netbeans to create a web service and using Glassfish as the server to test it within netbeans.
I have a file that i wish the web service to be able to read data from and possibly write to it. But where do i put the file. If 'course' is my netbeans project root i have tried placing the file in the following locations:
\Course
\Course\xml-resources\jaxb\FlightRequest
\Course\web
\Course\web\WEB-INF
\Course\src\java\org\me\FBooking
\Course\build\web
\Course\build\web\WEB-INF
\Course\build\web\WEB-INF\classes
and tried accessing it in the web service in my unmarshalling code using (as the file i am trying to access is an xml document):
un = (AvailableFlights) unmarshaller.unmarshal(new java.io.File("AvailableFlights.xml"));
But it cant find the file
So where am i supposed to place it?
If you need to write to the file, you should locate the file outside of your deployable code.
If you only need read-only access, putting the file in web/ will make the file accessible from a web browser. That may not be what you want.
If you put the file under WEB-INF/classes, it will be accessible to your code, but not publicly exposed.
Your code fragment for accessing the file will only work for files on the file system, and not for files you deploy as part of the WAR, so you need to look into other ways of loading the file if you decide to package it as part of your WAR.
Take a look at
getClass().getResourceAsStream("file")
which should be able to read from files within a WAR file. (Haven't tested it right now..) But this is only for reading from the file.

My Applet will not run in a browser

Can anyone help me out. I've written a program that controls the heating system in an imaginery house, an applet actually. it runs fine in netbeans but i cant get it to run as an applet in a browser, can anyone help me out please, I linked to a zip folder of all my code...
http://dl.dropbox.com/u/47863/Heating%20System.zip
http://alcaeos.com/applet/classes/MyHomeHeating.class -> 404.
Or to put that another way.
The applet element is telling the JRE to look for the class at the URL mentioned above.
The class is not at that location. (Neither is it in the same directory as the HTML.)
Where is the class file?
BTW: Typical bloody Netbeans generated code (/HTML). When what it generates is not invalid, it is redundant.
code="MyHomeHeating.class" The code attribute should not include .class.
<HR WIDTH="100%"> An HR element normally spans the entire width of the page.
You need to compile your applet into .class files (not .java files like you have in the ZIP; those are source code) and embed it into an HTML page. You can use the tag in HTML to do these; read more here: http://www.echoecho.com/applets01.htm

Categories

Resources