How to load an applet jar file?

Hello everyone,
I have an applet that uses my own jar file and approximately 6 third party jar files. I set up jar indexing (jar -i) which will download the jar files when they are needed. All seems to work well, but now I want to manually load the jar files which I cannot get working.
When the applet starts, about 1/2 of the jar files are downloaded (because they are needed at startup). I then want to load the additional jar files in the background, after the gui is initialized. I have tried this using the below thread which is executed from within the applet's start method:
// Try to load additional jar files in background by loading a class from each jar file.
Thread loadClass = new Thread() {
  public void run() {
    System.out.println("Loading classes...");
    try {
      // Tried loading classes this way, doesn't work.
      getClass().getClassLoader().loadClass("pkg1.Class1");
      getClass().getClassLoader().loadClass("pkg2.Class2");
      getClass().getClassLoader().loadClass("pkg3.Class4");
      getClass().getClassLoader().loadClass("pkg4.Class4");
      /* Loading classes this way doesn't work either.
      Class.forName("pkg1.Class1");
      Class.forName("pkg2.Class2");
      Class.forName("pkg3.Class3");
      Class.forName("pkg4.Class4");
    catch(ClassNotFoundException e) {
      // First attempt to load a class (pkg1.Class1) throws exception.
      System.out.println("Can't find class: " + e.getMessage());
loadClass.start();As you can see from above I am trying to load a class from each of the jar files so that the jar files would load into memory/cache. Unfortunately, it cannot find the classes. These are the errors from the java console:
Loading classes...
Loading: pkg1.Class1
Connecting http://my.server.com/my_dir/pkg1/Class1.class with no proxy
Connecting http://my.server.com/my_dir/pkg1/Class1.class with cookie "JSESSIONID=some_big_long_char_list"
Can't find class: pkg1.Class1
So it appears the jar file is not being downloaded. When I take away the dynamic jar loading (removing the "jar -i" & adding them all to the applet archive list) the thread executes correctly. So I know the class names, etc, are correct. How does one load an applet jar file?
Any help/suggestions are appreciated.

The above error I posted was because I forgot to index the jar files. That is why it couldn't find the jar file. I thought I was getting farther along with my problem, but I apparently just forgot to index the jars. I am now getting the problem that I got yesterday...
The applet freezes/hangs when it hits the thread. The GUI never opens (even though I'm running this thread right after the gui shows). The java console quits responding and the applet just stays the grey screen. I also tried the invoke later that you suggested.
public void start() {
  // ...initialize gui...
  // Applet freezes and remains grey, also the java console freezes.
  javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      System.out.println("Loading classes...");
      try {
        // When I comment out the below forName calls, the thread will still run evidenced through the done print statement.
        Class.forName("pkg1.Class1");
     Class.forName("pkg2.Class2");
     Class.forName("pkg3.Class3");
     Class.forName("pkg4.Class4");
        System.out.println("...Done loading classes");
      catch(Exception e)     {
        System.out.println("Can't find class: " + e.getMessage());
}

Similar Messages

  • How to load class from jar file dynamically?

    After I run my Java applicatoin, I need configuring the classpath of jvm to load some classess inside a jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know where the jar file is, what the jar file name is. All depends on the user to tell the jvm the details through some UI. I've tried to write: System.setProperty("java.class.path", "c:\myClass.jar");Class.forName("MyClass"); but failed.
    Can you tell my why and how?
    Thx

    After I run my Java applicatoin, I need configuring
    the classpath of jvm to load some classess inside a
    jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know
    where the jar file is, what the jar file name is. All
    depends on the user to tell the jvm the details
    through some UI. I've tried to write:
    System.setProperty("java.class.path",
    "c:\myClass.jar");Class.forName("MyClass"); but
    failed.That won't work. By the time it gets to your code it already has a copy of the original. You can't change it (short of modifying the JVM.)
    Can you tell my why and how?The usual way is to use a custom classloader.
    You can start by looking at java.net.URLClassLoader.

  • Applet : How to use Images in Jar file

    I want to put all images into a jar file to improve speed of loading.
    But how to invoke images from Jar file?
    Thanks.

    @Op. It's very important for a developer to know how to find information, and that skill usually comes with experience. Google is one of the best ways to find information and solutions to the most common problems.
    Kaj

  • How can i download these jar files to load SQL server derive

    Hi
    pls tell me how can i download these jar files and from what site i can do that to enable to load SQL server driver
    msbase.jar
    msutil.jar
    mssqlserver.jar

    if u use sqlserver 2000 u can download for free from microsoft.com
    and other sites are freetds.com i guess

  • Question about Java Applet Jar file signing.

    These questions pertain to Java 6 Standard Edition 1.6.0_22-b04 and later.
    I have gone through the Oracle Java Tutorial for generate public and private key information
    to sign a jar file, and how to sign the jar itself, all at
    [http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html|http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html]
    , and seek some clarification on the following related questions:
    -In order to "escape" the java applet sandbox that exists around the client's
    copy of the applet running in their web browser, ie.
    (something forbidden by default), is verification of the signed applet enough, or is a policy file required
    to stipulate these details?
    -using the policytool policy file generator, what do I need to add under "Principals"
    (if anything) when dealing with a Java applet? Are Codebase and SignedBy simply author information?
    -If I choose to use a java.security.Permission subclass object set up in equivalent fashion within the Applet,
    which class within the Applet jar do I instantiate that object in? Does it need to be mentioned
    in the applet's jar Manifest.MF file?
    -Is the "keystore database" a java language service/process which runs in
    the Server's memory and is simply accessed and started by default
    by the client verifier program (appletview/web browser)?
    -The public key certificate file (*.cer) is put in the webserver directory holding
    the Applet jar file (ie. Apache Tomcat, for example).
    -Presumably, the web browser detects the signed jar
    and certificate file, and provides the browser pop up menu asking the user
    about a new, non recognised certificate (initially).
    Is this so?
    -With this being the case, can the applet now escape
    the sandbox, be it with or without the stipulated
    policy permissions?

    848439 wrote:
    -In order to "escape" the java applet sandbox that exists around the client's
    copy of the applet running in their web browser, ie.
    (something forbidden by default), is verification of the signed applet enough, or is a policy file required
    to stipulate these details?Just sign the applet, the policy file is not necessary.
    -Is the "keystore database" a java language service/process which runs in
    the Server's memory and is simply accessed and started by default
    by the client verifier program (appletview/web browser)?No.
    -The public key certificate file (*.cer) is put in the webserver directory holding
    the Applet jar file (ie. Apache Tomcat, for example).No. For a signed Jar, all the information is contained inside the Jar.
    -Presumably, the web browser detects the signed jar
    and certificate file, and provides the browser pop up menu asking the user
    about a new, non recognised certificate (initially).
    Is this so?No. It is the JVM that determines when to pop the confirmation dialog.
    -With this being the case, can the applet now escape
    the sandbox, ..Assuming the end-user OK's the trust prompt, yes.
    ..be it with or without the stipulated
    policy permissions?Huh?

  • How to load an applet in card?

    Hi everyone,
    I use NetBeans and its JavaCard Simulator, protocol T = 0, and I am wandering how to load an applet using APDU tool instead of clicking on Run Projetc which do the mentioned thing. It would be helpfull if someone post ouptut and explain all used apdu commands.
    Thanks,
    Mare.

    Here is the APDU trace:
    Select Card Manager
    => 00 A4 04 00 08 A0 00 00 00 03 00 00 00 00
    <= 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65
        01 FF 90 00
    Authenticate
    cm>  init-update 255
    => 80 50 00 00 08 09 41 55 62 DF F5 61 2B 00
    <= 00 00 C6 D8 6A 1C B2 02 14 13 FF 02 00 00 93 73
        3A B8 2C 0F 8E A4 1D EF 84 60 77 12 90 00
    cm>  ext-auth plain
    => 84 82 00 00 10 B5 AA A8 E6 8B 73 57 F9 5D 37 6C
        D1 FE CF 56 32
    <= 90 00
    Install For Load
    => 80 E6 02 00 12 05 11 11 11 11 11 08 A0 00 00 00
        03 00 00 00 00 00 00 00
    <= 00 90 00
    Load Block 1
    => 80 E8 00 00 FF C4 82 01 65 01 00 1A DE CA FF ED
        02 02 04 00 01 05 11 11 11 11 11 0A 68 65 6C 6C
        6F 57 6F 72 6C 64 02 00 21 00 1A 00 21 00 0A 00
        0B 00 2A 00 0E 00 A1 00 0A 00 17 00 00 00 5A 02
        5A 00 00 00 00 00 00 01 01 00 04 00 0B 01 02 01
        07 A0 00 00 00 62 01 01 03 00 0A 01 06 11 11 11
        11 11 11 00 08 06 00 0E 00 00 00 80 03 00 FF 00
        07 01 00 00 00 1C 07 00 A1 00 01 10 18 8C 00 04
        7A 05 30 8F 00 09 3D 8C 00 02 18 1D 04 41 18 1D
        25 8B 00 03 7A 04 22 18 8B 00 07 60 03 7A 19 8B
        00 06 2D 1A 04 25 75 00 6D 00 06 00 00 00 1D 00
        01 00 2C 00 02 00 3B 00 40 00 4A 00 41 00 57 00
        42 00 62 19 8B 00 05 3B 19 03 1A 07 25 8B 00 08
        70 49 19 8B 00 05 3B 19 03 1A 07 25 8B 00 08 70
        3A 19 8B 00 05 3B 19 03 1A 07 25 8B 00 08 70 2B
        03 32 04 8D 00 00 32 1F 8D 00 01 70 1E 05 8D 00
        00 32 1F 8D 00
    <= 00 90 00
    Load other Blocks with  80 E8 00 xx ... which xx is the Block number
    Load Last Block
    => 80 E8 80 01 6A 00 01 70 13 03 8D 00 00 32 1F 8D
        00 01 70 08 11 6D 00 8D 00 01 7A 08 00 0A 00 00
        00 00 00 00 00 00 00 00 05 00 2A 00 0A 06 80 08
        10 06 80 07 01 06 00 00 01 03 80 03 02 06 80 03
        00 03 80 0A 06 03 80 0A 01 03 80 03 03 03 80 0A
        08 01 00 02 00 09 00 17 00 00 00 13 05 06 04 0A
        07 07 25 09 06 09 06 09 08 05 06 05 06 05 08 00
    <= 00 90 00
    Install For Install
    cm>  install -i 111111111111  -q C9#() 1111111111 111111111111
    => 80 E6 0C 00 1A 05 11 11 11 11 11 06 11 11 11 11
        11 11 06 11 11 11 11 11 11 01 00 02 C9 00 00 00
    <= 90 00Note that if you want to use APDU manually, you should do the authenticate process and loading all blocks of the CAP file yourself.
    Note that this is the APDU for a real card that is executed in JCOP Environment. I think it should work for the simulators too except the authentication commands.

  • How to get resources from jar-files

    Hi
    in my app I load an image via the Toolkit.getImage() method.
    Works fine if the app and the image are in folders on disk.
    It fails to load the image, if the app (and the image) is packed in a jar file.
    How can I get the image from there?
    I try to get the image as follows:
    String s = getClass().getResource("MyApp.class").getFile();
    AppPath = s.substring(0,s.lastIndexOf("/"));
    String PathToImages = "/images";
    MyImage = (Image)Toolkit.getDefaultToolkit().getImage(AppPath+PathToImages+"/logo32.gif");The App starts and works, it just fails to load the images.
    Any solutions??
    thanx in advance
    Herby

    This is actually pretty easy. First a little background.
    A Jar file is just a Zip file, with a few constructs for Java.
    The getResource() method is used to create a mapping to data within the Jar file, but is actually not necessary after you know how the mapping works.
    Just to give you an example of getResource:
    // returned is a url to the resource you want from your Jar file.
    URL myURL = MyClass.class.getResource("images/myimgage.gif");
    // then you can use this URL to load the resource
    Image img = getImage(myURL);If you were you look at the value of myURL you would see something similar to the followiing.
    jar:http://www.mywebsite.com/mydir/myjarfile.jar!/images/myimage.gifJust to break it down for you.
    The line always starts with the word jar:
    Followed by the path to your jar file.
    A sepearator !/
    Then the file you are loading from the Jar file.
    jar:     path_to_jar_file     !/     path_to_resource_in_jar_fileSo if you'd like, you could just create a URL object, and define the path to the object using the above method rather than using getResource.
    Anyway, back to your code. What I would do is print out what you get for:AppPath+PathToImages+"/logo32.gif"I'm thinking you might be getting 2 "/" in your path because I think:AppPath = s.substring(0,s.lastIndexOf("/"));will leave the "/" at the end and the next line you add the "/" in front of the image directory name. So you my have the following for your image path.mypath//images

  • How to access the database jar file using the derby 10.2.1.6 database ?

    Hi,
    How to access the database jar file using the derby 10.2.1.6 database ?
    I have used like below. And i am getting the following the error:
    "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.apache.derby.jdbc.EmbeddedDriver'
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)"
    My context.xml file looks like this:
    <Context crossContext="true">
    <Resource name="jdbc/derby" auth="Container"
    type="javax.sql.DataSource" driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
    url="jdbc:derby:jar(\CalypsoDemo\database.jar)samples"
    username="xxx" password="xxx" maxActive="20" maxIdle="10"
    maxWait="-1"/>
    </Context>
    What could be the reason.?
    Any suggestions will be appriciated.
    Thanks in Advance,
    Gana.

    ya, I have restarted. Can you please tell me whether the path which i am giving is right or not in the context file?
    Thanks,
    Gana.

  • Cipher.getInstance closes Applet JAR file.

    I am trying to use a Cipher in a signed Applet in java plugin-1.4 under I.E. Once I execute a Cipher.getInstance the applet jar file is closed and I cannot create any new classes that havent been previously loaded from it. The classloader ends up returning an "IlleagleStateException: Zip file closed".
    Is this a known bug? Is there a workaround? Perhaps a way to re-open the JAR file.
    I have been combing the FAQ's without finding any other refrences to the problem.

    I haven't found a solution to the original problem but for someone else that is looking for a workaround for this. I found that if I use two JAR with my Cipher in the second one, I can still load class files out of the first. I.E. <PARAM NAME = java_archive VALUE = "supportClasses.jar,mainApplet.jar"> where mainApplet.jar contains the code that uses the Cipher.

  • Multiple repeat downloads of applet jar file

    We have an applet that is downloaded from a Weblogic server. The applet is packaged as a jar file. Some of the testers have been complaining that the applet is extremely slow to start up.
    The applet start-up involves three phases. In a first phase, it fetches data from the server. This phase seems to execute in pretty much constant time. During the second and third phases, it constructs a UI using Swing objects. The UI includes some JPEG files, which are extracted from the applet's own jar file.
    Testers report that the slow part of start-up is actually the UI setup. This should theoretically not be network-bound at all. But packet tracing reveals that during this phase, there's a large amount of network traffic going on. It turns out that there are multiple GET requests for the applet jar file being issued. Typically, 29 requests are issued in all; just for reference, the applet is required to extract 28 images from its jar file, so it looks as if the additional requests correspond to image requests.
    One further detail: this does not occur where there is a fast connection to the server. In these cases, the applet is downloaded once. It looks as if the problem only occurs on slower network connections, and the speculation here is that the applet jar is somehow being downloaded only partially, so that requests for images somehow trigger a re-request of the jar file.
    Has anyone seen anything similar and, more to the point, is there a fix or workaround?
    Technical details: Internet Explorer 5.5 or 6.0, JRE version 1.4.2_01 Java HotSpot(TM) Client VM (on the client), WebLogic 8.1 (on the server)
    Thanks in advance for any help.

    Ok.
    I have been trying hard and found the solution. One of the ablove posting says that it works under java 1.4.1 plug-in. That's infact absolutely true. It also says that how to run client using JRE 1.4.2 or higher. That can be solved two. This is definitely a bug with the 1.4.2 plug-in.
    Follow this procedure that will solve the mystry.
    ----------------------start ---------------------------------
    Problem
    Download of applet is very slow
    Why?
    This was happening because of the repeated download of the applet jars by the applet plug in controller. It is quite clear that the Java 1.4.2 plug in controller has a bug that causes the plug in to download same jar files multiple times irrespective of Jar cache in the client side (configurable from client side using the Java plug in control panel) is enabled or disabled. Therefore, we have moved from 1.4.2 plug in to 1.4.1 (controlled from our client (JSP) code) that works fine.
    What the client (applet client) should do?
    You must do the following in the client side in order to avoid the long download time for applet when running from a browser. We have also found that the browser actually do not matter in slow applet downloads. It is only the plug in that does control the applet download.
    Irrespective of what JVM you have already installed (or not yet installed) please do the following:
    1. Download the JRE 1.4.2 from http://java.sun.com/products/archive/index.html
    -At the time of its installation if it shows that the "JRE is already installed do you uninstall it?" Go ahead and uninstall the JRE 1.4.2. After the un-installation again install the JRE 1.4.2
    -If it does not have the JRE 1.4.2 already installed, then you will see any warning window and you will be able to install the 1.4.2 JRE successfully.
    2. Now, go to the same link and install JRE 1.4.1.
    -If this JRE already installed, uninstall first like the step 1 above. then reinstall it.
    3. Now, after successful installation of the JRE 1.4.1, open the Plug-In control panel.
    -You will find the list of control panel(s) in the Start->Control Panel window. Use the control panel that shows the version number 1.4.1. If no version number shown then use the one that do not show any version number at its end.
    4. Do the following on the Plug-In control panel.
    -Verify if this is the 1.4.1 plug in control panel? Go to the "About" tab to see if it shows 1.4.1.
    If it does not show the 1.4.1 (or 1.4.1_x) then plug in was not installed correctly. Reinstall the 1.4.1 JRE following the step in no-2
    -Go to "Basic" tab and select "Show console" radio button.
    -Go to "Advanced" tab and from the drop down select "JRE ...1.4.2" from the "Java Runtime Environment" drop down box.
    -Go to "Browser" tab and select all that in the "Settings" box applicable for browsers.
    -Go to "Cache" select "Enable Caching" if it is not selected currently. Select "Unlimited" from "Size" options.
    Now hit "Apply" button at the bottom and close the control panel using the 'X'.
    5. Restart your Windows machine.
    6. You are ready to run the applet from any of the browser (IE, NS, etc.)
    --------------------------end------------------------------

  • How can i run a jar file as EXE on mouse click..

    *{color:#0000ff}how can i run a jar file as EXE on mouse click..is it possible in any way?????????{color}*

    amrit_j2ee wrote:
    *{color:#0000ff}how can i run a jar file as EXE on mouse click..is it possible in any way?????????{color}*Do you mean converting it from a jar file to an EXE file or do you mean that you would like to run the application by just double clicking it?
    If it's the latter then you need to make the jar file including a manifest.
    The manifest can be just a txt file with its content to be something like this:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: Somebody
    Main-Class: NameOfTheMainClass
    Class-Path:
    X-COMMENT: Main-Class will be added automatically by buildTo make the jar file including the manifest, use something like this in your command prompt (of course you must have compiled your java file(s) first):
    jar cfm test.jar MANIFEST.txt NameOfTheMainClass.classAfter that you'd be able to run your application just by double clicking it.
    If you're a NetBeans user, you can build your standalone application by right-clicking your project and then going to properties => run => and choosing a Main class. After that right click on that project and "Clean and Build", locate the jar file in the "dist" folder and double click it =]
    Hope it helps,
    LD

  • How to load an Applet application for 1000cards?

    Hi Friends..
    I want to know How to load an Applet application for 1000cards?..
    Assume that, i have an Applet application that need to loaded into 1000cards..
    So, how to solve this?
    Do i must to load an application manually for each card?
    Is there any another way?
    Thanks in advance..

    for 1000 cards you can use a "small" printer like an evolis "dualis" or something like that
    we've produced thousands of cards with this method in my company.
    the pro is that you can also print the cards in the same time.
    they usually have simple APIS like get_new_card_from_loader(), put_card_on_contacts(), eject_card()
    you can connect any reader on the printer , the raw card contacts are available on a connector.
    some printers also have contactless couplers.
    but remember that deploying cards in the field is not just loading an applet.
    it's also a cryptographic challenge, you need to change the card keys or anyone will be able to play with your cards, adding and removing applets as they want.
    typically this is achieved by using an ultra secret mother key and whatever derivation algorithm you like using data from INIT UPDATE as diversifier. example, you can TDES cipher part of the INIT UPDATE data using the mother key as TDES key, or use something involving SHA1, using a HSM if you are serious, etc.
    for your entertainment here is a high volume card personnalization machine. That's amazing.
    http://www.youtube.com/watch?v=6ZBF_yKRF5w

  • How do you create a jar file in JDeveloper 11.1.2.0.0

    How do you create a jar file in JDeveloper 11.1.2.0.0

    1) Select the project for which you would like to generate the jar.
    2) Right Click the selected right and select 'Project Properties'
    3) Select the 'Deployment' in the left tab.
    4) Click on 'New' to create a new deployment profile and in the popup dialog, select 'Jar File' profile type and provide the name.
    5) Press 'ok' to save the changes.
    6) Select the project and right click and select 'Deploy to' and select the jar profile name you have specified.
    The Jar library is generated and the full path to the library jar is shown in the log window.
    Thanks,
    Navaneeth

  • How to call function in jar file?

    First, I can't write english well.(I'm korean.. ) sorry about that.
    I have known function in jar file.
    but I don't know how to call function in jar file.
    how can I this work?
    My project and another project are respectively developing D-project with me and other man.
    so i need it. or I can't do this work.
    I will paste other's source code in my source code.
    and then recomplie , build it.. but it is not my wish!
    thanks for reading my sentence.

    If you have a jar file with a class that you wish to use, then you must add the jar file to your class path ($CLASSPATH on unix, linux, etc. and %CLASSPATH% on Windows).
    Then you can use the class normally, just as you would if it were not in the jar.
    If you meant something else, you'll need to explain what you meant.

  • How to use javap with jar files ?

    how to use javap with jar files ?
    thanks

    As long as the jar is on the class path, your gold. So,
    javap -classpath myjar.jar mypackage.MyClass
    Chuck

Maybe you are looking for