"Jar " contents?

Hi!
In reference to "jarring up" my app, does the jar only contain the referenced import statements?
In other words, is there extra API or librarys that are not being used by my app also just sitting in there taking up space?
Thanks!

> OK ... but what i'm trying to understand is that if
my app does not explicitly call for a certain
function of the java language, are these funtions not
included in my finished "jarred" app?
The only files that will be in the JAR file will be the ones you put there (and possibly a manifest).
http://java.sun.com/docs/books/tutorial/deployment/jar/index.html
~

Similar Messages

  • Handle unclosed after reading jar content

    Hi
    While attempting to build a simple dynamic plugin (or 'service', as in sun terminology) framework for my app,
    I encountered a behavior which seems at least unwanted to me:
    After opening a stream using a java.net.URL to a file inside a jar file, closing it wont close the handle on the jar file.
    To make it easy, here is a simple piece of code that causes the problem:
    public static void main(String[] args) throws IOException {
              InputStream inputstream = null;
              BufferedReader bufferedreader = null;
              try {
                   // URL to a local jar file
                   // the jar and service file do exist
                   URL url = new URL("jar", "", "file:/d:/temp/jars/ri.jar!/META-INF/services/test.plugin.Plugin");
                   inputstream = url.openStream();
                   bufferedreader = new BufferedReader(new InputStreamReader(inputstream, "utf-8"));
                   // do some stuff
              } finally {
                   if (inputstream != null) {
                        inputstream.close();
                   if (bufferedreader != null) {
                        bufferedreader.close();
              // force garbage just in case
              inputstream = null;
              bufferedreader = null;
              System.gc();
              System.gc();
              // pause before exit
              // at this point, there is still a handle on the jar file from the JVM
              System.out.print("pause;");
              Scanner in = new Scanner(System.in);
              in.nextLine();
         }When reaching the 'pause' step, a handle exists on the file and makes any action on it impossible
    (replacing it with a new one for instance). To confirm this, Process Explorer detects a handle from
    the javaw process associated with this program on the jar file.
    I've experienced this using the latest of jdk 6 and also with java 5 (on win XP)
    So, is this a normal behavior ? Any idea how to avoid it ?
    As I'm looking for dynamic plugin functionnalities, I'd like to keep this jar content as it is,
    ie this file which lists implementations of the "test.plugin.Plugin" service among the classes
    which are also stored in the jar.
    Being able to release the jar file would mean I can replace it with another version on fly,
    without restarting my app, and load it again to access the updated functionnalities, then
    unload it again and so on.
    Thanks in advance for any piece of advice on this issue.

    in case anyone is interested, I seemed to have found a workaround, by disabling caching for the URL connection:
    if we replace
    inputstream = url.openStream();
    bufferedreader = new BufferedReader(new InputStreamReader(inputstream, "utf-8"));
    // do some stuffwith
    final URLConnection connection = url.openConnection();
    inputstream = connection.getInputStream();
    bufferedreader = new BufferedReader(new InputStreamReader(inputstream, "utf-8"));
    // do some stuff
    connection.setDefaultUseCaches(false);the handle on the jar file is not kept after closing stream.

  • Can I change the Jar contents trough Java code ?

    It may seems a little bit wierd, but it could solve a lot of acessibility problms....
    Can I change/set the jar contents using java code ?
    My real problem: I'm creating a EDI Client and using a XML file as configuration file. It's running well but this XML is much exposed to unauthorized users....
    Can I set a value in this XML file if it is inside a jar file ??

    you can look at class JarOutputStream . You could also use class RunTime to just create a new jar with the proper files via the normal jar command.

  • Accessing Jar contents

    Hi everyone,
    I'm sorry to ask such a dumb question, but I'm still e newbie with Java.
    Ok here goes:
    How can I access the contents of a Jar file, for example images in a package, like:
    com.mypackage.images ----> images that I need to access.
    I used the example of images for simplicity but the contents of the jar file could be anything, like database drivers, or other classes.
    Thank you in advance.
    Chris

    It's really quite easy; if your entire application is in the same jar-file it will be just as if you weren't using jars at all. To use classes in a different jar-file, that jar-file just has to be put in the classpath-variable, and all the classes inside will be accessible.
    Not sure what you meant about the images - if you were talking about a class named images, a package or actual images to be loaded. In the latter case, there are a few differences from otside of a jar-file:
    // If your images are outside the jar:
    Image img1 = Toolkit.getDefaultToolkit().getImage("nameOfImage.png");
    // If your images are inside the jar:
    Image img2 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("nameOfImage.png"));

  • Protect Jar Content

    Can I use any tool or utility to make a content of a JAR file not accessible to unzip?

    RAUL_MORALES wrote:
    Can I use any tool or utility to make a content of a JAR file not accessible to unzip?No

  • Webutil.Jar Contents

    Can anyone explain why the following files are required in Webutil.jar :
    i1.jpg
    i2.jpg
    i3.jpg

    Can anyone explain why the following files are required in Webutil.jar :
    i1.jpg
    i2.jpg
    i3.jpg

  • Controlling JAR contents

    Is there a way of controlling what Workshop puts inside an EJB JAR (i.e. preventing
    it to include stubs and skeletons)?

    Hello,
    If your application can be packaged into an EAR file I recall sometime I employed the standard application.xml file (that tells the container to load each module in the order specified therein).
    Nevertheless that addresses a deploy time issue, not runtime like this one. If you are using OC4J 10.1.3, you can edit the deployment plan for your WAR file; in the webAppClassLoader wizard you can change the "searchLocalClassesFirst" or "includeWarManifestClassPath" setting. By finding adequate values for those above and by using the shared libraries mechanism accordingly you may work it out.
    RB

  • Rt.jar content

    Hi,
    In J2SE/jre rt.jar we find all Java public language organized in packages like java.subpackage or javax.subpack.
    But what's about lot of other packages like com.sun.xxxx or sun.xxxxx ?
    Are they necessary tu run the JVM ? What do they bring for developper ? Are they for compatibility ?
    Thanks

    Hi,
    Thanks, you gave me some ideas ; but I'm still puzzled. Of course, I never risk this on a platform but suppose I remove the packages other than java.xxx and javax.xxxx, what would happen ?
    Are this packages "reference implementation" ?
    If these package are absolutely necessary to the JVM, why aren't they in Java language itself ? is there a question of licensing ?
    Thanks by advance.

  • Jar Content

    Hi fellow Java developers, I'm making an application and I need to save an image inside the jar file so the application can use it. The IDE I'm using is Eclipse. Des anyone know how to save the image inside the jar file? I know this is possible because I extracted the jar file of Minecraft, a popular first person sandbox game, and the images for all the components of the game were in there.
    Thanks.

    Ok, I put it in the root folder, but I'm not sure what path to put in when I create an instance of File to access it. What path do I need to use to access files in the root folder?
    I thought I should create a mock situation, just to put in some names.
    Project name: project
    Image name: pic.jpg
    Path to image: ~/documents/eclipse/project/pic.jpg
    How should I access the file?

  • JRE 1.7 / Java Plug-in - Long delay in retrieving the applet File(JAR) due to a request to the Domain Controller(on port 53)

    Description:
    A specific group of users/customers (using Windows7 OS with IE and FireFox web browsers) are facing problems with retrieving the applet File, after they upgraded the JRE on the system(PC) to JRE 1.7.0_25-b17 from JRE version 1.6.0_29-b11.
    With JRE 1.7.0_25-b17 it is noticed that when the Java plugin requests for the applet File; it sends a request to the Domain Controller of the user, which causes a delay of 2 to 5 minutes and sometimes hangs. The problem occurs consistently.
    The current temporary workaround for this group of users is to use JRE version 1.6.0_29-b11.
    Problem analysis:
    To investigate the problem the below steps were executed:
    1) Collected the Java console outputbelow details from the user's system. (The complete output is not posted due to lengthy content, though can be added further to this post if required.)
    (a) Works fine with JRE version 1.6.0_29-b11. Kindly refer to Java console output in the code ‘section A’ towards the end of this post.
    (b) The problem occurs with problem with JRE version 1.7.0_25-b17. Kindly refer to Java console output in the code ‘section B’ towards the end of this post. The step where the problem is observed, is indicated as(##<comment>##).
    2) The network settings in the user's browser was checked. Internet Options > Connections > LAN setting
    The configured option is 'Use automatic configuration script' and the value is http://www.userAppX.com/proxy.pac
    This configuration remains the same irrespective of the JRE version in use.
    3) The network settings in the Java Control Panel was checked.
    The used/selected option is "Use browser settings", although values for 'Use proxy server' and 'use automatic proxy configuration script' are filled-in as 'user-proxy.com' and 'http://www.userAppX.com/proxy.pac' respectively.
    This configuration remains the same irrespective of the JRE version in use.
    4) The proxy PAC file was checked and debugging was done for the request 'https://myAppletHost.com/download/...'. The FindProxyForUrl function (including the conditions defined in it, for the hostname and domain checks) returns PROXY user-proxy.com:80
    5) The user also tried the below
    a. Changed the option in the network settings in the browser to 'Proxy server' with Address 'user-proxy.com' and Port '80'
    b. Restarted the browser.
    c. Tried with Java Plug-in 1.6.0_29, JRE version 1.6.0_29-b11. There was no problem and no request to the Domain Controller of the user.
    d. Tried with Java Plug-in 10.40.2.43, JRE version 1.7.0_40-b43. The problem occurs with the delay and a request to the Domain Controller of the user is observed.
    Kindly refer to Java console output in the code ‘section C’ towards the end of this post.
    6) The user also tried setting the below property in the Java Control panel; restarted the browser, and try with JRE 1.7.0_40-b43. The problem stil persists.
    -Djava.net.preferIPv4Stack=true
    7) The Global Policy Management of the Domain Controller was verified by the user. It has GPO for proxy setting but nothing related to Java security.
    Questions:
    The problem seems be specific to a particular (user) environment setup, and the user faces the problem when using JRE 1.7.
    We would like to know if the issue is in the (user) environment setup or in JRE 1.7.
    Could you please help with information/ideas/suggestions to identify the root cause and solution for this problem?
    Section A:
    Java Plug-in 1.6.0_29
    Using JRE version 1.6.0_29-b11 Java HotSpot(TM) Client VM
    User home directory = C:\Users\userA
    basic: Plugin2ClassLoader.addURL parent called for https://myAppletHost.com/download/myApplet.jar
    network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
    network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-b1bb5056c5b0e83f=2; Path=/"
    network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-b1bb5056c5b0e83f=2; Path=/"
    security: Loading Root CA certificates from C:\Program Files (x86)\Java\jre6\lib\security\cacerts
    security: Loaded Root CA certificates from C:\Program Files (x86)\Java\jre6\lib\security\cacerts
    security: Loading SSL Root CA certificates from C:\Program Files (x86)\Java\jre6\lib\security\cacerts
    security: Loaded SSL Root CA certificates from C:\Program Files (x86)\Java\jre6\lib\security\cacerts
    security: Loading certificates from Deployment session certificate store
    security: Loaded certificates from Deployment session certificate store
    security: Loading certificates from Internet Explorer ROOT certificate store
    security: Loaded certificates from Internet Explorer ROOT certificate store
    security: Checking if certificate is in Deployment denied certificate store
    network: Connecting https://myAppletHost.com/download/myApplet.jar with cookie "JSESSIONID=0000IK4bEMoqXH10zsl88rwvoRI:175oe9tjd; BCSI-CS-b1bb5056c5b0e83f=2"
    network: Downloading resource: https://myAppletHost.com/download/myApplet.jar
                    Content-Length: 403.293
                    Content-Encoding: null
    Dump system properties ...
    https.protocols = TLSv1,SSLv3
    java.vm.info = mixed mode, sharing
    java.vm.name = Java HotSpot(TM) Client VM
    java.vm.specification.name = Java Virtual Machine Specification
    java.vm.specification.vendor = Sun Microsystems Inc.
    java.vm.specification.version = 1.0
    java.vm.vendor = Sun Microsystems Inc.
    java.vm.version = 20.4-b02
    javaplugin.nodotversion = 160_29
    javaplugin.version = 1.6.0_29
    javaplugin.vm.options =
    os.arch = x86
    os.name = Windows 7
    os.version = 6.1
    trustProxy = true
    deployment.proxy.auto.config.url = http://www.userAppX.com/proxy.pac
    deployment.proxy.bypass.local = false
    deployment.proxy.http.host = user-proxy.com
    deployment.proxy.http.port = 80
    deployment.proxy.override.hosts =
    deployment.proxy.same = false
    deployment.proxy.type = 3
    deployment.security.SSLv2Hello = false
    deployment.security.SSLv3 = true
    deployment.security.TLSv1 = true
    deployment.security.mixcode = ENABLE
    Section B:
    Java Plug-in 10.25.2.17
    Using JRE version 1.7.0_25-b17 Java HotSpot(TM) Client VM
    User home directory = C:\Users\userA
    basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@12adac5
    basic: Plugin2ClassLoader.addURL parent called for https://myAppletHost.com/download/myApplet.jar
    network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
    network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-2d4ce94a2ae7b460=2; Path=/"
    network: Connecting http://10.x.x.xx:53/ with proxy=DIRECT
                    (##THE ABOVE REQUEST CAUSES THE DELAY OR HANGS##)
    network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-2d4ce94a2ae7b460=2; Path=/"
    security: Loading Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
    security: Loaded Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
    security: Loading SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
    security: Loaded SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
    security: Loading certificates from Deployment session certificate store
    security: Loaded certificates from Deployment session certificate store
    security: Loading certificates from Internet Explorer ROOT certificate store
    security: Loaded certificates from Internet Explorer ROOT certificate store
    network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
    network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-2d4ce94a2ae7b460=2; Path=/"
    network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-2d4ce94a2ae7b460=2; Path=/"
    network: Connecting https://myAppletHost.com/download/myApplet.jar with cookie "JSESSIONID=0000UQuXWY5tjxjpwcKHlfJKe_8:175oe9j45; BCSI-CS-2d4ce94a2ae7b460=2"
    network: ResponseCode for https://myAppletHost.com/download/myApplet.jar : 200
    network: Encoding for https://myAppletHost.com/download/myApplet.jar : null
    network: Server response: (length: -1, lastModified: Thu Feb xx yy:yy:yy CET 2013, downloadVersion: null, mimeType: text/plain)
    network: Downloading resource: https://myAppletHost.com/download/myApplet.jar
                    Content-Length: -1
                    Content-Encoding: null
    Section C:
    Java Plug-in 10.40.2.43
    Using JRE version 1.7.0_40-b43 Java HotSpot(TM) Client VM
    User home directory = C:\Users\userA
    basic: Plugin2ClassLoader.addURL parent called for https://myAppletHost.com/download/myApplet.jar
    network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
    network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-1d67c8b6508ca09c=2; Path=/"
    network: Connecting http://10.x.x.xx:53/ with proxy=DIRECT
                    (##THE ABOVE REQUEST CAUSES THE DELAY OR HANGS##)
    network: Checking for update at: https://javadl-esd-secure.oracle.com/update/blacklist
    network: Checking for update at: https://javadl-esd-secure.oracle.com/update/blacklisted.certs
    network: Checking for update at: https://javadl-esd-secure.oracle.com/update/baseline.version
    network: Connecting https://javadl-esd-secure.oracle.com/update/blacklist with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
    network: Connecting https://javadl-esd-secure.oracle.com/update/baseline.version with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
    network: Connecting https://javadl-esd-secure.oracle.com/update/blacklisted.certs with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
    security: Loading Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
    security: Loaded Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
    security: Loading SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
    security: Loaded SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacerts
    Dump system properties ...
    https.protocols = TLSv1,SSLv3
    java.vm.info = mixed mode, sharing
    java.vm.name = Java HotSpot(TM) Client VM
    java.vm.specification.name = Java Virtual Machine Specification
    java.vm.specification.vendor = Oracle Corporation
    java.vm.specification.version = 1.7
    java.vm.vendor = Oracle Corporation
    java.vm.version = 24.0-b56
    javaplugin.nodotversion = 10402
    javaplugin.version = 10.40.2.43
    os.arch = x86
    os.name = Windows 7
    os.version = 6.1
    trustProxy = true
    active.deployment.proxy.auto.config.url = http://www.userAppX.com/proxy.pac
    active.deployment.proxy.bypass.local = false
    active.deployment.proxy.http.host = user-proxy.com
    active.deployment.proxy.http.port = 80
    active.deployment.proxy.same = false
    active.deployment.proxy.type = 3
    deployment.browser.path = C:\Program Files (x86)\Internet Explorer\iexplore.exe
    deployment.proxy.auto.config.url = http://www.userAppX.com/proxy.pac
    deployment.proxy.bypass.local = false
    deployment.proxy.http.host = user-proxy.com
    deployment.proxy.http.port = 80
    deployment.proxy.override.hosts =
    deployment.proxy.same = false
    deployment.proxy.type = 3                                                                                                                                                                                                                                                            
    deployment.security.SSLv2Hello = false
    deployment.security.SSLv3 = true
    deployment.security.TLSv1 = true
    deployment.security.TLSv1.1 = false
    deployment.security.TLSv1.2 = false
    deployment.security.authenticator = true
    deployment.security.disable = false
    deployment.security.level = HIGH
    deployment.security.mixcode = ENABLE
    PS:
    Since the JRE 1.7.0_25-b17 update, it is noticed that when the Java plugin requests for the applet File; it sends a request to the Domain Controller of the user, which causes a delay of 2 to 5 minutes and sometimes hangs.
    The problem occurs consistently, and also with JRE 1.7.0_45-b18.
    Java Plug-in 10.45.2.18
    Using JRE version 1.7.0_45-b18 Java HotSpot(TM) Client VM
    User home directory = C:\Users\userA
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    cache: Initialize resource manager: com.sun.deploy.cache.ResourceProviderImpl@134a33d
    basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@1971f66
    basic: Plugin2ClassLoader.addURL parent called for https://myAppletHost.com/download/myApplet.jar
    network: Connecting https://myAppletHost.com/download/myApplet.jar with proxy=HTTP @ user-proxy.com/194.xxx.xx.xx:80
    network: Server https://myAppletHost.com/download/myApplet.jar requesting to set-cookie with "BCSI-CS-f797d4d262467220=2; Path=/"
    network: Connecting http://10.x.x.xx:53/ with proxy=DIRECT
    network: Connecting http://10.x.x.xx:53/ with proxy=DIRECT
                    (##THE ABOVE REQUEST CAUSES THE DELAY AND SOMETIMES HANGS##)

    My organization is experiencing very similar problems.  We have resolved it through several steps.
    We upgraded the client to Java 8 and we saw in the console that the hanging connection with the Domain Controller no longer occurs.  This may be all that is necessary for your environment as well. 

  • How to get the entries in a jar/zip file contained within a jar/zip file?

    If I want to list the jar/zip entries in a jar/zip file contained within a jar/zip file how can I do that?
    In order to get to the entry enumeration I need a Zip/JarFile:
    ZipFile zip = new ZipFile("C:/java_dev/Java_dl/java_jdk_commander_v36d.zip");
    // Process the zip file. Close it when the block is exited.
    try {
    // Loop through the zip entries and print the name of each one.
    for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
    ZipEntry entry = (ZipEntry) list.nextElement();
    System.out.println(entry.getName());
    finally {
    zip.close();
    Zip file "java_jdk_commander_v36d.zip" contains two zip entries:
    1) UsersGuide.zip
    2) JDKcommander.exe
    How to list the entries in "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip"?
    The following code:
    URL url = new URL("jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip");
    JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
    zipFile = (ZipFile)jarConnection.getJarFile();
    would point to "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip", which is no help at all and Class JarURLConnection does not have an enumeration method.
    How can I do this?
    Thanks.
    Andre

    I'm not sure I understand the problem. The difference between a zip and jar file is the manifest file; JarFile is extended from ZipFile and is able to read the manifest, other than that they are the same. Your code
    for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
    ZipEntry entry = (ZipEntry) list.nextElement();
    System.out.println(entry.getName());
    }is close to what I've use for a jar, below. Why not use the same approach? I don't understand what you're trying to do by using JarURLConnection - it's usually used to read the jar contents.
    String jarName = "";
    JarFile jar = null;
    try
        jar = new JarFile(jarName);
    catch (IOException ex)
        System.out.println("Unable to open jarfile" + jarName);
        ex.printStackTrace();
    for ( Enumeration en = jar.entries() ;  en.hasMoreElements() ;)
        System.out.println(en.nextElement());
    }

  • 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

  • Applet inside a JAR: Cannot access other classes within the JAR

    Hello,
    Description
    Web app + applet (packaged in a JAR)
    I have followed this tutorial
    JAR contents
    package mypackage
    SimpleApplet.class
    SimpleObj.class
    _"SimpleApplet" uses "SimpleObj"_
    package mypackage;
    public class SimpleApplet extends JApplet {
        @Override
        public void init() {
            SimpleObj obj = new SimpleObj();
    HTML code
    <applet archive="SimpleApplet.jar" codebase="." code="mypackage.SimpleApplet.class" width="800" height="600" />
    SimpleObj cannot be found (Java Console)
    java.lang.NoClassDefFoundError: mypackage/SimpleObj
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: mypackage.SimpleObj
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 8 more
    Caused by: java.io.IOException: open HTTP connection failed:*http://localhost:8080/SimpleApp/mypackage/SimpleObj.class*
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 12 more
    Exception: java.lang.NoClassDefFoundError: mypackage/SimpleObj
    It looks like JRE does not search for the SimpleObj class inside the JAR, but tries to get it from the server...
    Any ideas?
    Thanks in advance,
    Gerard
    Edited by: gsoldevila on Dec 10, 2008 2:05 AM

    misread, deleted
    Edited by: atmguy on Dec 10, 2008 1:12 PM

  • .JAR woes. It just refuses to work for me :-(

    I spent a week building a simple java app from a C program I wrote a couple of years ago. The process has not been without tears, but I've enjoyed it. That is, up until the point of trying to make it into an 'executable' jar file. No matter what I do, it would refuse to launch and give 'can't find blah..' errors. After a couple of days of this and getting nowhere, it's starting to hack me off seriously.
    To wipe out any oddness with my immature Java code, I dropped back to a 'hello world' basic program and tried again - but I still cannot get a working .jar out of it...
    PLATFORM: Debian Linux
    java version "1.6.0_14"
    Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
    Java HotSpot(TM) Server VM (build 14.0-b16, mixed mode)
    This is what I've done - can anyone spot the error?
    Directory /develop/java/package1
    contains:
    HelloWorld.java
    HelloWorld.java
    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello, World!");
    }This compiles to HelloWorld.class and it runs without any issue with:
    java HelloWorld
    from inside the /develop/java/package1
    {funny enough from anywhere else in the filesystem it *wont* run - eg: java /develop/java/package1/HelloWorld - I'm not sure if that is relevant or standard Java security}
    I have a manifest creation file in the parent directory (/develop/java/) that looks like this:
    Main-Class: HelloWorld.classTo give it an Entry Point.
    I try to create a simple executable .jar by running the command:
    jar vcmf manifest HelloWorld.jar package1From the: /develop/java/ directory. This runs without error and creates HelloWorld.jar
    jar vcmf manifest HelloWorld.jar package1
    added manifest
    adding: package1/(in = 0) (out= 0)(stored 0%)
    adding: package1/HelloWorld.java(in = 124) (out= 101)(deflated 18%)
    adding: package1/HelloWorld.class(in = 427) (out= 289)(deflated 32%)
    Checking the /META-INF/MANIFEST.MF shows:
    Manifest-Version: 1.0
    Created-By: 1.6.0_14 (Sun Microsystems Inc.)
    Main-Class: HelloWorld.classBut trying to execute it with: java -jar HelloWorld.jar throws:
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class
    Caused by: java.lang.ClassNotFoundException: HelloWorld.class
         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: HelloWorld.class. Program will exit.
    I've tried altering paths, where I create the jar from etc, but it persists and after days of looking at this, I'm starting to wish I never bothered. What the hell am I missing here? It has to be staring me in the face?

    mike120 wrote:
    package1 is the directory - not a package name (that is, part of the path) - sorry for any confusion.It does not matter. The directory in the Jar, and the package name, must be identical. So do it one way or the other.
    1) package1 package.
    Source:
    package package1;
    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello, World!");
    Jar content:
    jar tvf HelloWorld.jar
    0 Tue Dec 01 09:16:58 GMT 2009 META-INF/
    95 Tue Dec 01 09:16:58 GMT 2009 META-INF/MANIFEST.MF
    0 Tue Dec 01 08:24:14 GMT 2009 package1/
    124 Tue Dec 01 08:24:12 GMT 2009 package1/HelloWorld.java
    427 Tue Dec 01 08:24:14 GMT 2009 package1/HelloWorld.class
    Manifest:
    Main-Class: package1.HelloWorld2) No package.
    Source:
    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello, World!");
    Jar content:
    jar tvf HelloWorld.jar
    0 Tue Dec 01 09:16:58 GMT 2009 META-INF/
    95 Tue Dec 01 09:16:58 GMT 2009 META-INF/MANIFEST.MF
    124 Tue Dec 01 08:24:12 GMT 2009 HelloWorld.java
    427 Tue Dec 01 08:24:14 GMT 2009 HelloWorld.class
    Manifest:
    Main-Class: HelloWorld

  • Problem Compiling JAR Loaded in Oracle 10g

    I have loaded a JAR file into my Oracle 10g database using the following command-line:
    Loadjava -force -oci8 -order -resolve -schema "MYSCHEMA" -user "USER/PASSWORD@HOST" -verbose "JarFile.jar"
    Unfortunately, after loading the JAR contents, the resolution of the individual files never completes. The process runs for >24 hours. Is there a better way to complete this task? I have even tried compiling portions of the JAR file via Toad, but it appears the recursive nature of the dependencies causes the process to essentially hang.
    Unless the JAR files compiles successfully, I can load my Java source code but my resulting Java stored procedures cannot compile because of my import references to the JAR file. My java code was compiled for JDK1.3 using JDeveloper 10.1.3.0.0 to eliminate conflicts with the Oracle JDK (JDK1.4). Is there a setting or a flag which would allow compilation of my source code without compiling the JAR file to utilize the Oracle JIT compiler?
    Any assistance/suggestions would be greatly appreciated. Thank you.

    Avi,
    Thank you for the suggestion. As a result, I found how to load my JAR (iText JAR file) file without decompressing using loadjava -jarasresource MYJAR.jar but now the issue of referrencing this resource within my Java class so that it will compile once loaded into the database. Here is sample of my objects:
    Oracle User-Defined Type:
    CREATE OR REPLACE TYPE schema."BLOB_ARRAY" as varray(20) of BLOB
    Java Source:
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED schema."JavaSource" AS
    import com.lowagie.text.Document;
    import com.lowagie.text.pdf.PdfCopy;
    import java.io.ByteArrayOutputStream;
    import java.io.*;
    public class JavaSource{
    public static Document doc;
    public static ByteArrayOutputStream baos = new ByteArrayOutputStream();
    public JavaSource(){}
    public static PdfCopy getDoc(oracle.sql.BLOB[] docs){
    PdfCopy writer = new PdfCopy(doc, baos);
    return writer;
    LOADJAVA:
    loadjava -force -schema "SCHEMA" -user "user/password@sid" -verbose -resolve -unresolvedok -genmissing -jarasresource -genmisingjar "C:\JavaSource.java" "C:\iText.jar"
    Oracle Package:
    CREATE OR REPLACE PACKAGE schema."JavaSource" AS
    FUNCTION getDoc(param1 schema.BLOB_ARRAY) return PdfCopy AS Language Java Name 'JavaSource.getDoc(oracle.sql.BLOB[]) return PdfCopy';
    Oracle Function to query Database populating User-Defined type argument:
    CREATE OR REPLACE FUNCTION schema.TestRun() RETURN schema.BLOB_ARRAY AS
    tmpArray schema.BLOB_ARRAY := null;
    BEGIN
    tmpArray schema.BLOB_ARRAY := BLOB_ARRAY();
    cursor c_blob is select blob_content from schema.doc_table;
    BEGIN
    for blob_rec in c_blob loop
    tmpArray.extend;
    tmpArray(tmpArray.count) := blob_rec.blob_content;
    end loop;
    END;
    return tmpArray;
    END;
    I cannot get my class JavaSource to compile as VALID and therefore the Oracle Function schema.TestRun does not execute properly. Am I missing something? Assistance is greatly appreciated. Thank you.

Maybe you are looking for

  • IPod Classic won't sync or go into Disk Mode.

    My iPod suddenly decided to now work, and displays a red cross (X) on the screen. I looked up what to do, and apple.com told me to set to disk mode. I spent a few minutes reading it and looking up tutorial videos on how to do it, and mine will not co

  • HELP - AA7 upgrade to 7.1.0

    I've an annoying problem... with AA7, that is! Every time I restart my laptop (Vista HP) I get the windows installer pop-up for the Acrobat 7.1.0 upgrade which will not run - it just stops with an error (can't remember exactly which one, at present -

  • N86 8MP

    First time poster, Hello all. I have just got the N86 8MP phone and need to clear up a few things in my head. 1st why cant I store music files in E: Mass Memory as I have 6GB free 2nd is E: Mass Memory storage inbuilt on phone or is it on the interne

  • How do I send just a song to someone and not the entire album?

    How do I send just a song to someone and not the entire album??

  • "WebServiceServlet" failed to preload on startup

    Hi, I work on a WebService project based on Weblogic 8.1SP3. I generate my beans with the autotype task using a XSD. Then I generate the web-services.xml descriptor with the source2wsdd task. Here is a part of this XSD : <i><xs:schema targetNamespace