Buralek
Buralek

Reputation: 13

How to add jar into applet?

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."

Upvotes: 0

Views: 620

Answers (2)

Stephen C
Stephen C

Reputation: 718936

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:

Upvotes: 1

angel_navarro
angel_navarro

Reputation: 1777

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

Upvotes: 0

Related Questions