I am trying to use gson library with my applet but JRE(8u25) does not see the library and gives me this error:
MyAppSigned.jar is my signed applet
gson-2.3.1.jar is the library i am trying to use
Test WebPage Content (Test.html):
<html>
<body>
<applet code='test.XApplet' width=400 height=400>
<param name='ARCHIVE' value='MyAppSigned.jar,gson-2.3.1.jar'>
<param name='codebase' value='http://example.com/Commons'>
</applet>
</body>
</html>
Here is the content of the manifest file inside MyAppSigned.jar:
Manifest-Version: 1.0
Trusted-Library: true
Class-Path: gson-2.3.1.jar
Permissions: all-permissions
Created-By: 1.6.0_26 (Sun Microsystems Inc.)
Codebase: *
Name: test/XApplet.class
SHA1-Digest: qLHEgL7Or0Ja7Jn7iRZt2lJ/928=
Here is the content of commons directory on iis:
I tried with/without codebase attribute in my test webpage. it does not changed the error.
But if i copy gson-2.3.1.jar into the directory C:\Program Files\Java\jre1.8.0_25\lib\ext it Works without any error
what am i doing wrong?
First of all copy the jar in JRE_HOME/lib/extis not a good solution since then you've to copy this jar in all the client machines which will use your applet.
I think that the problem with your code is in your <applet> definition, you're using <param> to define archive, however in documentation archive and others are defined as attributes of <applet> tag, take a look at documentation. So try defining the <applet> as follows:
<html>
<body>
<applet code="test.XApplet" width="400" height="400"
archive="MyAppSigned.jar,gson-2.3.1.jar" codebase="http://example.com/Commons">
</applet>
</body>
</html>
Note that it's better to use <object> since <applet> tag will not be supported in HTML5, also think about use deployJava.js which can make more easy to deploy an applet in a different browsers.
Hope this helps,
Related
I am trying to run an Applet in a browser. I have three libraries, commons-net.jar, Jsch.jar (referenced) and MyApplet.jar, in the same folder on my local machine.
I created the following HTML file try.html:
<html>
<head>
<title>
HelloApplet by Aditya Jain
</title>
</head>
<body>
<Applet Code = 'com.cisco.fastforward.main/Main_Applet.class'
Archive = 'MyApplet.jar,commons-net-3.3.jar,jsch-0.1.51.jar'
Width =900 height = 900>
</Applet>
</body>
</html>
When I load the HTML file, it initially says "plug-in blocked". After I enable the plugin and reload, the page becomes unresponsive and I don't get any console output.
Update - The browser i was using was Chrome and Safari , When i switched to Firefox 25.0 , it worked after a few permissions.
I dont know why this happened.
Any reasons?(latest Chrome and Safari used)
Sign your jar. Set your system path to java path in cmd. Then run jarsigner, create a keystore and sign your jar. Make sure you have a proper manifest in your jar as well for permissions purposes. Also set java security to low and add your local html file to the java security exception list. This is the only way to make an applet work right now.
I have JApplet which use some jars. I have added these jars to lib folder of my applet, have set these to classpath and have created html:
<HTML>
<HEAD>
<TITLE>Applet</TITLE>
</HEAD>
<BODY>
<H1>Applet</H1>
<object classid="java:com.csat.CSATApplet.class"
type="application/x-java-applet"
archive="file:///C:\\Documents and Settings\\alburash\\Desktop\\CSAT_client_2.jar"
height="300" width="450" >
<PARAM NAME=ARCHIVE VALUE="dom4j-1.6.1.jar,poi-3.10-FINAL-20140208.jar,poi-excelant-3.10-FINAL-20140208.jar,poi-ooxml-3.10-FINAL-20140208.jar,poi-ooxml-schemas-3.10-FINAL-20140208.jar,poi-scratchpad-3.10-FINAL-20140208.jar,stax-api-1.0.1.jar,xmlbeans-2.3.0.jar,axis.jar,commons-discovery-0.2.jar,javax.wsdl_1.6.2.v201012040545.jar,jaxrpc.jar,org.apache.commons.logging_1.1.1.v201101211721.jar,org.apache.xmlrpc_3.0.0.v20100427-1100.jar,saaj.jar">
</object>
</BODY>
</HTML>
But when I start this html I see error "java.lang.NoClassDefFoundError:javax/xml/rpc/Service". I understand that the applet can't find this class, but why does it happen? When I start the applet via Eclipse it works correct. All needed libraries are into "lib" folder into CSAT_client_2.jar , classpath is correct, CSATApplet.class have been found(it was my previous problem).
It's unsigned applet.
For Stephen C: I have tried to change html and the applet can't find CSATApplet.class and don't start. When I use my first html, the applet finds CSATApplet.class without problem and starts, but after that I see my first error. My main problem is that I can start applet, but the applet doesn't find jar files with needed libraries.
<HTML>
<HEAD>
<TITLE>Applet</TITLE>
</HEAD>
<BODY>
<H1>Applet</H1>
<object classid="java:com.csat.CSATApplet.class"
type="application/x-java-applet"
codebase="file:///C:/Documents%20and%20Settings/alburash/Desktop/CSAT_client_2.jar"
height="300" width="450" >
</object>
</BODY>
</HTML>
Also, when I start the applet in Eclipse I see warning, but the applet starts and works correctly:
"Apr 30, 2014 2:09:06 PM org.apache.axis.utils.JavaUtils isAttachmentSupported
WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled."
According to the HTML 4.0.1 spec, section 13.3, the "archive" attribute is a space separated list of URLs. The implication is that it is the list of URLs for the JARS that comprise the applet's classpath.
Consider putting all of the JARs into one directory and using the "codebase" attribute so that you can use relative URLs in the "archive" URL list.
Your "file:" URL is malformed. A well-formed Windows "file:" URL looks like this:
file://laptop/My%20Documents/FileSchemeURIs.doc
or
file:///C:/Documents%20and%20Settings/davris/FileSchemeURIs.doc
Note that:
the path separator in a hierarchical URL is "/", and not "\" or "\",
any space characters need to be %-escaped.
Finally, I could not find any justification in the spec or in the Oracle pages on applets that would support using a <param name='archive' ... > element to specify the applet classpath.
Reference:
File URLs in Windows
You can use applet tag:
<applet codebase="."
code="com.csat.CSATApplet.class"
archive="CSAT_client_2.jar,dom4j-1.6.1.jar,poi-3.10-FINAL-20140208.jar,poi-excelant-3.10-FINAL-20140208.jar,poi-ooxml-3.10-FINAL-20140208.jar,poi-ooxml-schemas-3.10-FINAL-20140208.jar,poi-scratchpad-3.10-FINAL-20140208.jar,stax-api-1.0.1.jar,xmlbeans-2.3.0.jar, axis.jar,commons-discovery-0.2.jar,javax.wsdl_1.6.2.v201012040545.jar,jaxrpc.jar,org.apache.commons.logging_1.1.1.v201101211721.jar,org.apache.xmlrpc_3.0.0.v20100427-1100.jar,saaj.jar"
height="300"
width="450">
</applet>
By this way, both the HTML page and JAR files must have in same directory
I am trying to run an .jar file with a class in it that extends Applet in an html file. The .jar is called DocScrabble.jar, html is DocScrabble.html, and .class file is ScrabbleSolver.class. ScrabbleSolver.class also references a file called EnglishWords.txt, and I included that in the default package in which I placed ScrabbleSolver.class when I exported the file to a .jar. DocScrabble.jar and DocScrabble.html are located in the same directory. The applet works fine in eclipse, so I am assuming that my html file is the problem. THere is the html code.
<!DOCTYPE html>
<html>
<head>
<title>Doc Scrabble></title>
</head>
<body>
<APPLET CODE="ScrabbleSolver.class"
ARCIHVE="DocScrabble.jar"
WIDTH="400"
HEIGHT="200"
</Applet>
</body>
</html>
When i try to run the html, it gives me an error that says ClassNotFoundException ScrabbleSolver.class. Could someone please tell me what's wrong? I'm relatively new to programming.
It is highly advisable to check HTML using a validation service or DTD.
I typically rely on the W3C HTML validation service to check HTML.
Note that the applet element was last valid in HTML 3.2. It was deprecated in HTML 4.01. Without declaring any version, that mark-up would be presumed to be HTML 5.
The best way to deploy an applet is to use the Deployment Toolkit Script. On the other hand mistakes in spelling the attribute names in the script would not be picked up by an HTML validation service, since it concentrates on the HTML, rather than JavaScript embedded in the HTML.
For that reason it is a good idea to see the applet work when loaded using 'pure HTML' first.
Is your ScrabbleSolver class in a package? if so then it should be packagename.ScrabbleSolver.class
See Also: http://download.java.net/jdk8/docs/technotes/guides/jweb/applet/using_tags.html
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
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.