Applets and classes in jar files

I have placed an applet and a group of classes that the applet uses in a jar file.
The classes are grouped in their own files in a short directory tree within the jar file.
When the applet is loaded by the browser on a client with the usual CODE="appletname.class" and ACRCHIVE="jarname.jar" statements, are the related class files and the directory tree also loaded into the client? Or do they remain at the server to be used by the applet as necessary?

I'd say the entire JAR will be downloaded.

Similar Messages

  • How to create and use library JAR files with command-line tools?

    Development Tools -> General Questions:
    I am trying to figure out how to put utility classes into JAR files and then compile and run applications against those JAR files using the command-line javac, jar, and java tools. I am using jdk1.7.0_17 on Debian GNU/Linux 6.0.7.
    I have posted a simple example with one utility class, one console application class, and a Makefile:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130520-2134.tar.gz
    Here is a console session:
    2013-05-20 21:39:01 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-20 21:39:12 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/hello/HelloConsole.java
    package com.example.hello;
    import static com.example.util.Hello.hello;
    public class HelloConsole {
        public static void main(String [] args) {
         hello("world!");
    2013-05-20 21:39:21 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -f hello
    find . -name '*.class' -delete
    javac src/com/example/util/Hello.java
    javac -cp src src/com/example/hello/HelloConsole.java
    echo "java -cp src com.example.hello.HelloConsole" > hello
    chmod +x hello
    2013-05-20 21:39:28 dpchrist@desktop ~/sandbox/java/jar
    $ ./hello
    hello, world!I believe I am looking for:
    1. Command-line invocation of "jar" to put the utility class bytecode file (Hello.class) into a JAR?
    2. Command-line invocation of "javac" to compile the application (HelloConsole.java) against the JAR file?
    3. Command-line invocation of "java" to run the application (HelloConsole.class) against the JAR file?
    I already know how t compile the utility class file.
    Any suggestions?
    TIA,
    David

    I finally figured it out:
    1. All name spaces must match -- identifiers, packages, file system, JAR contents, etc..
    2. Tools must be invoked from specific working directories with specific option arguments, all according to the project name space.
    My key discovery was that if the code says
    import com.example.util.Hello;then the JAR must contain
    com/example/util/Hello.classand I must invoke the compiler and interpreter with an -classpath argument that is the full path to the JAR file
    -classpath ext/com/example/util.jarThe code is here:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130525-1301.tar.gz
    Here is a console session that demonstrates building and running the code two ways:
    1. Compiling the utility class into bytecode, compiling the application class against the utility bytecode, and running the application bytecode against the utility bytecode.
    2. Putting the (previously compiled) utility bytecode into a JAR and running the application bytecode against the JAR. (Note that recompiling the application against the JAR was unnecessary.)
    (If you don't know Make, understand that the working directory is reset to the initial working directory prior to each and every command issued by Make):
    2013-05-25 14:02:47 dpchrist@desktop ~/sandbox/java/jar
    $ cat apps/com/example/hello/Console.java
    package com.example.hello;
    import com.example.util.Hello;
    public class Console {
        public static void main(String [] args) {
         Hello.hello("world!");
    2013-05-25 14:02:55 dpchrist@desktop ~/sandbox/java/jar
    $ cat libs/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-25 14:03:03 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -rf bin ext obj
    mkdir obj
    cd libs; javac -d ../obj com/example/util/Hello.java
    mkdir bin
    cd apps; javac -d ../bin -cp ../obj com/example/hello/Console.java
    cd bin; java -cp .:../obj com.example.hello.Console
    hello, world!
    mkdir -p ext/com/example
    cd obj; jar cvf ../ext/com/example/util.jar com/example/util/Hello.class
    added manifest
    adding: com/example/util/Hello.class(in = 566) (out= 357)(deflated 36%)
    cd bin; java -cp .:../ext/com/example/util.jar com.example.hello.Console
    hello, world!
    2013-05-25 14:03:11 dpchrist@desktop ~/sandbox/java/jar
    $ tree -I CVS .
    |-- Makefile
    |-- apps
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.java
    |-- bin
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.class
    |-- ext
    |   `-- com
    |       `-- example
    |           `-- util.jar
    |-- libs
    |   `-- com
    |       `-- example
    |           `-- util
    |               `-- Hello.java
    `-- obj
        `-- com
            `-- example
                `-- util
                    `-- Hello.class
    19 directories, 6 filesHTH,
    David

  • Can I increase heap memory without specify any class or jar file??

    Hi,
    I tried to increase my heap memory in this way :
    java -Xms256m -Xmx256m
    but I got an error ... it's seem that I must specify a class java or a .jar file ...
    This is the error :
    Usage: java [-options] class [args...]
    (to execute a class)
    or java [-options] -jar jarfile [args...]
    (to execute a jar file)
    where options include:
    -client to select the "client" VM
    -server to select the "server" VM
    -hotspot is a synonym for the "client" VM [deprecated]
    The default VM is client.
    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
    A ; separated list of directories, JAR archives,
    and ZIP archives to search for class files.
    -D<name>=<value>
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version and exit
    -version:<value>
    require the specified version to run
    -showversion print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
    include/exclude user private JREs in the version search
    -? -help print this help message
    -X print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
    enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
    disable assertions
    -esa | -enablesystemassertions
    enable system assertions
    -dsa | -disablesystemassertions
    disable system assertions
    -agentlib:<libname>[=<options>]
    load native agent library <libname>, e.g. -agentlib:hprof
    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
    load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
    load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
    show splash screen with specified image
    can I increase heap memory without specify any class or jar file??
    thx

    chiara wrote:
    Hi,
    I tried to increase my heap memory in this way :
    java -Xms256m -Xmx256m
    but I got an error ... it's seem that I must specify a class java or a .jar file ...
    This is the error :
    Usage: java [-options] class [args...]
    (to execute a class)
    or java [-options] -jar jarfile [args...]
    (to execute a jar file)
    can I increase heap memory without specify any class or jar file??The job of java.exe is to execute java bytecode.
    What is it supposed to do with your request to use 256m of memory for heap
    when you are not giving it a class or a jar to run?

  • Ojvmtc reports xy.jar is not a class or jar file

    Hi
    I am a little bit confuced because ojvmtc reports an error I can not imagine about:
    oracle@cikic-desktop:~/Downloads/dom4j-1.6.1$ ojvmtc /u01/app/oracle/product/11.1.0/mds/jdk/jre/lib/jce.jar
    /u01/app/oracle/product/11.1.0/mds/jdk/jre/lib/jce.jar is not a class or jar file
    The set is closed
    But jce.jar is a jar file and I can inflate it:
    oracle@cikic-desktop:/tmp/fo$ jar -xf /u01/app/oracle/product/11.1.0/mds/jdk/jre/lib/jce.jar
    oracle@cikic-desktop:/tmp/fo$ ls -l
    total 8
    drwxr-xr-x 3 oracle oinstall 4096 2010-05-03 19:40 javax
    drwxr-xr-x 2 oracle oinstall 4096 2010-05-03 19:40 META-INF
    And if I do a ojvm on a class file everything is working like expected:
    oracle@cikic-desktop:/tmp/fo$ ojvmtc javax/crypto/Mac.class
    The set is not closed
    96 classes are missing
    So It must be a configuration mistake somewhere ...
    Can you please help me out.
    Thanks
    Christian Maier

    Coole thanks, this works pretty well!
    Chris
    oracle@cikic-desktop:~$ cp /u01/app/oracle/product/11.1.0/mds/jdk/jre/lib/jce.jar /tmp/
    oracle@cikic-desktop:~$ ojvmtc /tmp/jce.jar
    The set is not closed
    131 classes are missing

  • Applets and 3rd party jars

    Hi,
    I'm trying to use a 3rd party jar with an applet. I can access the functions just fine when using an applet viewer, but when I try deploying the applet from a web page I get classNotFound exceptions. How do I go about getting the applet to recognize the jar file?
    Thanks

    Eva, yes, if that class in one of the 3rd party jars wants to access your class directly, then it is necessary that your class is loaded by the same classloader that loads that 3rd party jar or even higher up the classloader hierarchy.
    Why do you consider putting your class library into applib "a bit rude"? As long as your classes are named distinctively so that they will not clash with other classes, it is not a problem.
    On the other hand, it seems that the design of that 3rd party class is not classloader friendly. Had it used something like the following to load a class that is undefined at the compile time, you might not have this problem.
       Class userClass = Thread.currentThread().getContextClassLoader().loadClass(nameOfUserDevelopedClass);
       Object plugin = userClass.newInstance();

  • WAR Can't find class in JAR file in EAR/lib

    Hi,
    I have 1 EAR file with 1 WAR and 1 EJB-JAR file. Our main business-code is in a JAR-file which is placed in the EAR/lib/ folder along with the rest of the shared JAR-files.
    When i deploy the EAR the EJB gets deployed fine but when the WAR gets deployed, we get a ClassNotFoundException. We configured a class as a ServletContextListener (Which is part of the jar) in the web.xml so at startup it should perform some initiation. But since it can;t be found....
    I've tried changing the Mainfest.mf to include a CLASSPATH attribute with ./lib/x.jar but it stil the same problem. The only thing that solves it is to put it in the WEB-INF/lib folder.
    What am i doing wrong?
    Thanks,
    Maarten

    Here it is
    <?xml version="1.0"?>
    <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
    <application>
         <display-name>spg-online</display-name>
         <module>
              <web>
                   <web-uri>appname.war</web-uri>
                   <context-root>appname</context-root>
              </web>
         </module>
         <!--module>
              <ejb>appname-ejb.jar</ejb>
         </module-->     
    </application>
    My app follows the basic structure of an EAR-file:
    EAR
    META-INF
    application.xml
    lib
    appname.jar
    a.jar
    spring.jar
    appname.war
    appname-ejb.jar
    The meta-inf of the war-file looks like this:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.5
    Created-By: 1.4.2_08-b03 (Sun Microsystems Inc.)
    Class-path: ./lib/appname.jar ./spring.jar
    I let ANT generate the Class-path:
    <jar jarfile="${dist.home}/${component.name}.war">
    <fileset dir="${build.home.webroot}" />
    <!-- dependency -->
    <manifest>
    <attribute name="Class-Path" value="${lib.project.manifest.classpath}"/>
    </manifest>
    </jar>

  • Using classes in jar file

    I have added a jar file to my eclipse project, and inside the jar file are the classes I want to access, but when I try to import them into my classes, the import wont find them.
    How can I use an import statement on them?
    e.g. import ocss.nmea.api.NMEAReader;
    the import cannot be found, but ocss is inside a jar file that I put in the lib file of my project.
    Thanks

    JoachimSauer wrote:
    Did you just put the jar in your project or did you add it to your build path (the build path is the Eclipse way to configure the classpath).Thanks, added the build path.
    ;)

  • How can i set the dos can compile and excute the jar file?please help?

    How can i set the dos prompt can compile my .java file and execute my jar file.

    Go to where you downloaded your Java SDK. Look around for a button labled "Installation." Click the button. Download the installation instructions. Read them. Then read them again.

  • Applets and classes and jars

    ok, this has probably been asked and answered a million times, but I cannot find it anywhere.
    heres my problem:
    I have an applet and am trying to run it from internet explorer and all I get is a blank screen. the code is:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" CONFILTERED="text/html; charset=windows-1252"></meta>
    <title>Segregation of Duties</title>
    <link type="text/css" rel="stylesheet" href="department.css"/>
    <style type="text/css">
    body {
    background-color: #528cff;
    a:link { color: #528cff; }
    <applet code=mypackage.SODApplet.class archive=deploy.SODApplet.jar Height=300 Width=300>
    </applet>
    </style>
    </head>
    <body></body>
    </html>
    Apparently it cannot find the class or the jar. But how do I tell it where to find them?
    The class is in c:/jdevinstall/jdev/mywork/SOD/SODReports/classes/mypackage
    and the jar is in
    c:/jdevinstall/jdev/mywork/SOD/SODReports/deploy/
    the html is on my desktop
    Richard

    Nothing to do with Servlets here... but:
    The Applet JAR has to be in a path relative to the web page, or the server root. You are asking the client (the web browser the user is using) to download the JAR and look inside for the class to run. So the web browser must be able to see that JAR. As such it needs to be in a directory your server hosts. The easiest is to have it in a directory relative to the page that displays it, such as:
    Web Hosted Directory:   C:\Web\HostedDir\
    Web page location                       \MyApp\SODAppletPage.html
    JAR file location                       \MyApp\lib\SODApplet.jar
    Applet tag
        <applet code="mypackage.SODApplet.class"
                archive="lib/SODApplet.jar"
                Height=300 Width=300>
        </applet>

  • Adding all dependent classes of an applet to make a jar file

    Hi everyone,
    I have this problem which I was not able to find a solution for, So I truly appreciate any feedback on this.
    I have a project on eclipse which is basically an applet.
    This applet is using some classes in some jars that I have imported as libraries for this project.
    Everything works on eclipse with no problem. However I need to make a jar file of the applet and required classes to use it in an html page.
    Now that's the part I have been facing difficulties, cuz I have to include all the classes that the applet is using from other jar
    files. And I can not come up with a way to find out all those classes.
    On the other side if I include the whole jars then my applet goes over 100 meg and would be useless.
    I am going to give an example of the problem I have in hope of making it a bit clear.
    I have a applet, which uses some classes from some jars. i.e., class A. but class A itself need class B and etc.
    Now how can I find all these dependencies since I have to include them along the applet in the jar file I am going to make.
    Once again I appreciate any feedback and sorry that is a long question.

    Fractalz wrote:
    . . . Now that's the part I have been facing difficulties, cuz I have to include all the classes that the applet is using from other jar
    files. And I can not come up with a way to find out all those classes.See the Class-Path: parameter (of a Manifest file) documentation here:
    http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Manifest-Overview

  • How to modify a specific class in jar file ?

    I've downloaded a jar file for applet, the jar file works fine... but when I extract a specific class file from the jar file and just recompie it from my IDE (Eclipse) without even making any change and then compress again jar class files including the new modified class file instead of the old one (without any modifications to other classes)... then I get
    (NoSuchMethodError ) exception whenever methods of other classes are invoked from within the modified class !!
    ...The manifist file of the jar file reads the following line
    Created-By: 1.4.0_01 (Sun Microsystems Inc.)
    I thought it means that jar class files were built using JDK 1.4.0_01 ...I used JDK 1.5.0_01 in my IDE...
    I thought JRE incompatiblity was the reason of the problem so I downloaded JRE 1.4.0_01 and used it to build this class file... but i got the same exception..
    so what is the main reason of the problem ? ...should I make changes to IDX files accompanying applet jar files ??
    If no, then how can I overcome this problem and be able to change and rebuild a specific class from this jar file ?
    (I cannot rebuild all classes in jar because there are errors I cannot resolve !!)

    Could you please clarify: do you want to run your project or a project from an independent jar?
    In the first case just select Run Project from the project context menu or select a class with main method and click Run File in the class context menu.
    Regarding the second case:
    - I don't think there is such a feature in the IDE (running third party jars is not an IDE function). Could you explain why you need this?

  • Classes in JAR file not found

    Okay, so I am somewhat new to Java, and I've never used a JAR file before. However, I need to make an applet with access to the local machine, so I've got to put it in a JAR file so I can sign it and blah, blah, blah . . .
    Anyhow, my understaing is that I write
    <APPLET
    CODE = DisplayClass.class
    ARCHIVE = display.jar
    HEIGHT = x
    WIDTH = y>
    </APPLET>
    then use java.sun.com's html converter to make the tag like
    <!--"CONVERTED_APPLET"-->
    <!-- CONVERTER VERSION 1.3 -->
    <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = 800 HEIGHT = 450 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
    <PARAM NAME = CODE VALUE = DisplayClass.class >
    <PARAM NAME = ARCHIVE VALUE = "display.jar" >
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
    <PARAM NAME="scriptable" VALUE="false">
    <COMMENT>
    <EMBED type="application/x-java-applet;version=1.3" CODE = DisplayClass.class ARCHIVE = "display.jar" WIDTH = 800 HEIGHT = 450 scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT>
    Man, you need a new browser, one that can display applets
    </NOEMBED></EMBED>
    </OBJECT>
    <!--
    <APPLET CODE = DisplayClass.class ARCHIVE = "display.jar" WIDTH = 800 HEIGHT = 450>
    Man, you need a new browser, one that can display applets
    </APPLET>
    -->
    <!--"END_CONVERTED_APPLET"-->
    In any event, whenever I try to view it, with either IE or Netscape, the browser can't find the .class file in question.
    The JAR file contains all the classes in the base directory. I'm really at a loss as to what I'm doing wrong, since all the docs I can find seem to indicate this should work.

    What's all this about DisplayClass.class being in a
    package? It was my understanding that classes are
    always part of packages. DisplayClass.java (the
    uncompiled DisplayClass) certainly refers to itself as
    being in a package, with the first line being package
    testapplet;So your DisplayClass is in the package testapplet. Then you have to move DisplayClass in a folder named testapplet, or compile as
    javac -d . DisplayClass.java
    which will then create that folder for you and place the class file inside that.
    The jar file should then keep the class in the same folder structure
    testapplet/DisplayClass
    And your CODE tag should refer to
    testapplet.DisplayClass
    If you didn't add the package statement to your DisplayClass.java file, then it would be in a default package and you wouldn't have to place the class file in a folder.

  • Problem finding class in jar file

    I have an applet that will run when I have all the classes sitting in the same directory. ex) http://IPaddress/directory. But I try to put them all into a jar file and run the code and it says cant find the class. Below is my html code. Please help!
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    <APPLET
    CODEBASE="http://IPaddress/directory1/directory2"
    CODE="Applet.class"
    ARCHIVE="1stJar.jar,2ndJar.jar,3rdJar.jar,Applet.jar"
    WIDTH=600 HEIGHT=600>
    </APPLET>
    </BODY>
    </HTML>

    Where are your jar files contained? They need to be in the same directory as your CODEBASE, or otherwise include a relative directory.
    Also, what browser are you using?
    From the Java web page on APPLET tags
    "Unfortunately, not all browsers understand the same archive format or use the same HTML code to specify the applet archive"

  • Problem in loading applet from non executable jar file

    hello ,
    I am new to jar concept plz help.. I am trying to call an applet from another applet through frame it is working fine but its download time is much more. now i want to store all my images , sound files and class files of other applets in a jar file and want to access these inner applets from this jar file so that it will make only one http connection with the server for this jar file only and can reduce the download time of applet.
    Can anyone can give me suggestion plz..
    Thanx

    You have to download what you have to download. You
    probably can't easily share images between 2 separate
    Jar files. Unless you can expose them through the
    other applet via a method that can be known once you
    have the reference to the other applet.Thanx but i think i have to elaborate the problem :
    my project structure is just like this ::
    on the top is ::
    Applet A---> from this applet i am callling Applet B & Applet C in frame
    and communication is established between these 3 applets successfully .
    now i have made a single non executable jar file which contains images , sound and class files of these applets .
    so i am referencing images and sound files in applets through this jar.
    but i wanted to load Applet B & C through this jar file only.
    How can i do this ??
    Thanx .. I hope now the problem is clear

  • Java Plugin and GIFs from Jar file...

    This used to work and I haven't looked at it for a while. First thing I did is run the old java applet web page with the old jar file, kinda just to lay eyes on the thing again.
    It had to download a new plug-in from Sun, and upon doing so, reports a new error indicating that the value for the cache_version attribute in the HTML is incorrect. It was 1.0 (always has been) and the plugin says it needs to be in X.X.X.X format instead.
    So, that isn't a nice change to make in the plugin at this time. However, if I just click okay and close the error dialog, at least it works fine after that.
    In my attempt to get rid of the dialog I change the cache version to 1.0.0.0, upon doing this
    the toolbar images no longer load, it says there is a java.io.FilePermission error.
    We'll it doesn't make any sense that a mere change to cache version caused that so I changed the version back to the apparently erroneous value of 1.0, and then the toolbar images work again ! But I get the permission error.
    Any ideas how I can fix these pesky images loading from a jar ?
    Do you have any code that loads images out of a jar in an applet succesfully ?
    Or have any suggestions on what I could try ?
    Below is the code I'm using to load the images, where icoXXXX is a ImageIcon object, and fileameXXXX is a string containing a relative file path such as "images/highcolor/toc_color.gif" (this code executes in the applet's init() method (called by the plugin):
    java.net.URL urlToc = getClass().getResource(filenameToc);
    java.net.URL urlTocBW= getClass().getResource(filenameTocBW);

    dunno why but
    getClass().$blah... wouldn't work for getting images in an applet from a jar for me.
    But this does:
    Class c = Class.forName("java.lang.Object");
    InputStream in = c.getResourceAsStream("/images/myImage.gif");
    byte[] buffer = new byte[in.available()];
    in.read(buffer);
    icon = new ImageIcon(buffer);
    when included with the usual default exception handling.
    Lemme know if that doesn't work for you.
    cheers
    -Ragu
    Overweight is when you step on your dog's tail and it dies.

Maybe you are looking for

  • Power supply part number for Cisco 2900

    I need to know what are the part numbers for installing the redundant (second) power supply.

  • Do Leopard icons increase the file size?

    In programs like Photoshop you have the option of including a preview or a thumbnail icon for the image you're saving. This is important to know because, if you are making a web page or trying to fit as many files as possible on a disk, you want the

  • How can I get Numbers to retain last opened position across my devices?

    I am a regular user of Numbers on my iMac (mid-2010), my iPad v3 and iPhone 5s. Ever since Mavericks came in and the many iWork updates that happened alongside it I have been unable to keep the same cell position in sync across my devices. So when op

  • Start-process -arguments

    Hi, Can anyone see why this is running the program but not passing the arguments across.  It fires up but then closes, with no logs that I can find $startRichCopy = "C:\RichCopy4.0\RichCopy64.exe" $arguments = "d:\internal \\remotenas.qav-dr.com\QAV-

  • HT6010 Certificates of ios 7.0.3

    Under settings/general/about there is a certificate called Trust Store 2013080500.... I don't think it's on anyone else's phone cuz I've asked a couple people.  Underneath that there is an option that says learn more about certificates and when I cli