Could Java applet use other lib for web - java

This is web code for applet
<applet code=test.class name=test archive="thisDemo.jar">
</applet>
I write a class, and the class access the local data, so I use key to sign the applet. But I need to use other library, like Apache jar.
How to use the the jar in applet?
I can use the Apache jar in eclipse, but can't work in applet when web call the applet.

This works for me:
<applet code=test.class name=test archive="thisDemo.jar,apache.jar" width="800" height="600">
</applet>
and putting apache.jar next to thisDemo.jar
You might need to sign every single dependency jar:
https://stackoverflow.com/questions/14229863/must-sign-all-jars-of-applet

Related

Embedding multi-class applet with .jar

I have a multi-class applet that has been exported using Eclipse as a .jar file. The jar file is called chess.jar, and the class I compiled and ran from in Eclipse is called Chess.java, and the binaries are Chess.class. The following code is the HTML I am trying to use to embed this applet into my website.
<APPLET CODE=Chess.class
ARCHIVE="chess.jar"
WIDTH=700
HEIGHT=700
CODEBASE="mywebsitewherethefilesarebeinghosted.com/"
ALT="Your browser understands the <APPLET> tag but isn't running the applet, for some reason.">
Your browser is ignoring the <APPLET> tag!
</APPLET>
I get the error ClassNotFoundException Chess.class
I have done applets before that have only one class successfully here , and I am using almost exactly the same HTML except for the CODEBASE and I have added the ARCHIVE tag.
As an applet, it has no main class. I am not very familiar with the MANIFEST.MF file, and I'm not sure if I need to utilize it for this purpose. My Chess.class calls some other classes like Pawn.class and Knight.class and they are all in chess.jar. Any help would be greatly appreciated.
EDIT
I created a local HTML file that runs the .jar locally and it runs perfectly.
<html>
<applet code=Chess.class
archive="chess.jar"
width=700 height=700>
</applet>
</html>
I think it is a simple matter of the contents of your HTML. I see you have a second start tag that I think would be confusing the browser. The browser would think the first one does not have an end tag and that may be the reason it is being ignored. Remove that and try again.
Even if this isn't the problem it's bad practice to leave tags open like that. Your error message should also be a bit more meaningful for poor users who don't know what an applet tag is.
It seems that CODEBASE follows / as directory separator unlike . in case of CODE attribute
so try replacing your CODEBASE value with proper directory structure separated by /
check example here and here also

Applet in Google App Engine

My aim is to host my applet to google app enigne.
I have made a jar of my applet, I have placed the jar into WEB-INF/lib directory but still when I write applet tag in my jsp page as
<applet code="myPackage.MyClass" archive="myapplet.jar" width="600" height="480"/>
The applet is not showing in the browser.
I am using eclipse with GAE plugin
Please Guide me.
Try puttIng the JAR into the same directory as the JSP file.

How to use an applet with packages in a jar

I have an applet (Applet, not JApplet) that has a lot of classes organized into packages, including the applet itself. I have looked everywhere for how to use that jar as an applet. It is not runnable and has a manifest file like such:
Manifest-Version: 1.0
Class-Path: AppletSource.jar
I put it in an html (Game.html), as such:
<applet code="Game/Game.class" archive="Game.jar" width=800 height=600>
Your browser needs JAVA!!!
</applet>
As you can see the class is called Game.class, Package Game and the jar Game.jar.
The manifest is in Game.jar/META-INF
When I use the appletviewer Game.html I get an error (java.security.AccessControlException: access denied) and if I open the .html I get a ClassNotFoundException: Game.Game.class. What can I do?
try
<applet code="Game.Game" archive="Game.jar" width=800 height=600>
Your browser needs JAVA!!!
</applet>
Also check that the package name is really Game and not game.
The format for the applet code attribute is from oracle doc "The value appletFile can be of the form classname.class or of the form packagename.classname.class.".
This file is relative to the base URL of the applet. It cannot be absolute.
Also try adding the jar in the same directory as the html.
For some further information see this doc
http://docs.oracle.com/javase/1.4.2/docs/guide/misc/applet.html

Java applet runs locally but not on the host

I have written an applet application and integrate it to run under a webpage. It runs properly when I am running the webpage as local HTML file (using file:/// protocol). But when I am running it on a host (tested with http://localhost using XAMPP), it does not work anymore and through exception of ClassNotFound.
My applet classes are packaged under a *.jar file. Is not the jar file loaded in this case? Can anyone give me a suggestion that what can I do to deal with this problem?
Update
I have uploaded the jar file into the same folder as the HTML file. In my case, they are in the DocumentRoot of the Apache server. I can double-click on the HTML file, it works.
But when I query like: localhost/test.html, it does not. My code:
<applet
code="package/ClassName.class"
archive="appletfile.jar">
</applet>
I can able load the jar file by: localhost/appletfile.jar
Html document (in which <applet/> tag is used to deploy an applet) and .jar file must be in the same folder.
<applet code ="package.AppletClassName"
archive = "Sample.jar"
width = "200"
height ="200">
</applet>
I do not know why but when I change the name of *.jar file to lowercase (all lower case), then it works.
yes!!
Applets able to run in Apache PHP server.The applet is loading from server when you called the html file the applet execute in browser and gives the out put.must and should update your java plugin before run the applet in browser.put your entire applet folder in to apache htdocs folder ,then access that applet in browser....!!It will work.I am sure..
All the Best
Only self signed applets are able to access in browser with security other wise applet not execute with security.You have to signed the applet to execute.

Java applet won't load

I am building a small applet in java. It works fine (really!) when I run it in eclipse as an applet. Problems start when I export it as a jar and than try to load it through an html page.
Here's the html code:
<body>
<applet archive="myJar.jar" width=650 height=850>
</applet>
</body>
Now when I run other jar files in this way they work fine, for example if you view the source page of this niffty demo
<body>
<applet code="org.niffty.Niffty.class" archive="niffty.jar" width=650 height=850>
<param name="file" value="prelude.nif">
</applet>
</body>
Thank you!
You're missing the code attribute in your applet tag. Without it, the browser doesn't know which class in your JAR file is the applet it should display.
You've specified the archive, but no code attribute so the applet runner doesn't know which class to use as the entry point. You have to either specify code or specify the object attribute to give a serialized applet instance - but code is much more likely to be appropriate for you.
See the documentation for the applet tag for more information.

Categories