dcsimg
<strong>How can I load an applet and all the packages that I imported in it?</strong>
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Luca_Ventura
Posted On:   Sunday, July 29, 2001 09:45 AM

I have written an applet that import the following libraries with the statements: import java.io.*; import java.net.URL; import java.net.*; import java.applet.Applet; import java.awt.*; // Api that implement cryptographic functionalities written by IAIK import iaik.java.security.Security; import iaik.java.security.SecureRandom; import iaik.java.security.NoSuchAlgorithmException; import iaik.java.security.InvalidKeyException; import iaik.java.security.NoSuchProviderException; import iaik.java.security.KeyPair; imp   More>>

I have written an applet that import the following libraries with the statements:

			



import java.io.*;

import java.net.URL;

import java.net.*;

import java.applet.Applet;

import java.awt.*;


// Api that implement cryptographic functionalities written by IAIK


import iaik.java.security.Security;

import iaik.java.security.SecureRandom;

import iaik.java.security.NoSuchAlgorithmException;

import iaik.java.security.InvalidKeyException;

import iaik.java.security.NoSuchProviderException;

import iaik.java.security.KeyPair;

import iaik.java.security.KeyPairGenerator;



import javax.crypto.Cipher;

import iaik.security.provider.*;

import iaik.security.rsa.*;

import iaik.java.security.Provider;


// I have witten the following packages:

import Borsa.*;

import supporto.*;



When I load my Web Page that contains tha applet I receive the following error in the Java console:

			


java.lang.NoClassDefFoundError: iaik/java/security/Key

at java.lang.Class.newInstance0(Native Method)

at java.lang.Class.newInstance(Unknown Source)

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)



It verifies as soon as the applet must load the first package that doesn't belong to the Java 2 Runtime Library by Sun Microsystem.
In fact "iaik.java.security" is a package written by IAIK (http://jcewww.iaik.at/) that implements cryptographic functionalities and it is included
in the .jar file called "iaik_jce_full_ae.jar" that is the "applet edition" library for iaik-jce 2.6).


I am using Windows ME as Operating System, Netscape 6 as Web Browser, Apache 1.3.2 (for Windows) as HTTP Server.


I have some questions:


1)Does the Web Browser allow me to download all the code (classes) of the packages that the applet needs to work?


I suspect that the Web Browser let me to download only the code of the applet and not the code of all classes files that it imports (with the only exception of the classes included in the Java 2 Standard edition that the Java interpreter present in the Web Browser knows).


2) In this case: what does a user have to do to download correctly the applet?


3) Can I write my own packages (like "Borsa" and "supporto") and import them in the applet code?


4) What a user that connects to my web site must do to download the applet and all the packages
that it needs to work?


5)Is there a way to indicate to the Java Virtual Machine of the Browser the location of the packages that it must import together with the applet code?


With Internet Explorer I obtain the same error but this time with the "Borsa.*" package.
"Borsa" is a folder (and not a. jar or a .zip file) present in the same location where I put my applet code (.class) on my http server.
All the other .jar files that I included in the applet code are in a special folder on my http server that I indicated in the environment variable "CLASSPATH".


I inserted the applet in my web page in this way:


			



I hope someone can help me!Thank you very much in advance!!!


Luca Ventura

   <<Less

Re: <strong>How can I load an applet and all the packages that I imported in it?</strong>

Posted By:   Dermot_Hennessy  
Posted On:   Monday, July 30, 2001 02:11 AM

To address your questions as you asked them:
  1. If this were the case, almost no applet functionality would be possible on the Web. Of course this is not the case, so a Web Browser will allow you to download any Java code contained in any Jar as long as you tell it to. I'll come to this later.
  2. All the user should have to do to load the applet is hit the web page which starts it - so it's the web page that's important here.
  3. It is not really recommended to place individual class files on a webserver in this way, however it is possible as long as your directory structure reflects your package structure off the codebase directory.
  4. Yes. First you must understand the concept of a web server's virtual directory. This is a directory, or folder from which your web page loads. Different web servers offer different levels of functionality vis-a-vis virtual directories, but for the sake of simplicity, we will assume that there is only one now and it is contained in /httpdocs.

    Inside this directory will be contained your index.html file and all other files and folders required to render your web page.

    Let's say that you wish to gather all of your compiled code into a directory called /httpdocs/Progetto. In this case, you specify Progetto as your codebase in the html file which specifies your applet (as you have done in your example). This means that all class files and image files related to that appled will be searched for from that directory.

    However, the JVM doesn't just know what classes to load because the jar files containing them are contained in the codebase - you also need to specify exactly what jar files to load. You do this through the use of the ARCHIVE parameter. The use of this parameter differs from browser to browser - Netscape uses a construction like
    whereas IE uses a construction like
    By specifying the archives to load, you are telling your browser to pull down the required classes for your applet. So you need to
    (a) put all of the jar files required by your applet into the directory specified in the codebase attribute; and
    (b)specify iaik_jce_full_ae.jar, along with all other jar files required by your applet as archives that you want to download in your html file.


You might also like to refer to Where do I place the applet class files so that the browser finds them when it loads an HTML file with an APPLET tag? in the FAQ. A brief perusal of the FAQ did not yield any other relevant postings for me, but perhaps John can verify this?


Hope this helps,
Dermot

About | Sitemap | Contact