Adding a JAR within a JAR

Hi,
I am new to the JAR stuff and my question is quite simple (I guess).
Is it possible to add a JAR file when building another JAR file ?
I need for an applet to reference an external JAR file and I would prefer to avoid several JAR files (so as to keep distribution of the application as simple as possible).
Thanks a lot
Christophe

Either you ship multiple jars.
Or you unpack every jar, and build a big common jar.
Of course the last may bring you into conflicts with license-restrictions.

Similar Messages

  • How to update/replace Jars within sbconfig.jar during import

    Hi,
    I want to replace a jar file, used by java callout actions, during import. I am using WLST script to import configuration jar but cannot figure out how to replace jar file.
    That jar file contains environment specific properties which i intend to change as part of import, once config jar is uploaded and impoted within the same session.
    I have looked to Ref, ArchiveType, Refs, and ALSBConfigurationMBean, but cant figure out to replace specific jar file within imported config jar.
    Many thanks in advance!
    many thanks
    sal
    Edited by: sallo on 16-Feb-2010 07:40

    Hi vivik,
    I am already using custimization files to already to customize environment values etc. But what i need cannot be handled by the customization file.
    I want to replace a jar file (utility jar), already in the sbconfig jar, being referenced by Java Call out actions during import process. I am begining to convince myself that it is not possible to perform such action during import process. I have checked the MBeans API but not very helpful.
    I hope i have able to explain the problem here!
    many thanks
    sal

  • Deploying Java apps: Jars within a jar

    Dear Java gurus,
    Imagine I have a Java application. I wish to bundle it all within a jar file. The problem is, I also wish to add some dependencies, in the shape of a couple of other jars. This means that the user could run the app using the straight-forward "java -jar myapp.jar" command.
    So, I jar it all up. This Jar contains a MANIFEST.MF that specifies the main class, and also the classpath. ("Class-Path: lib/other.jar") as the extra jars were in a dir called lib within the jar.
    But, this doesn't work run as java complains about not being able to resolve classes that exist within other.jar.
    I have yet to find anything on the net beyond really basic examples of using jar. Anyone had more experience with it and can share some tips?

    Its a horrible thing. Basically, you can't include jars in jars.  I asked this question on the Java.sun.com forums a while ago if you want to search there. Its a common question and pisses people off.
    You have some other options:
    1: extract all dependency jars and include the classes in a single jar file.
    2: distribute multiple jars and set the Class-Path in the Manifest to point to them. Since you're pointing at lib/other.jar, you gotta use:
    myjar.jar
    lib/other.jar
    You won't find another way around this. I recall somebody suggesting that packaging jars with jars should be available in mustang, but as of yet, it is not so.
    Also, I would strongly recommend starting to use Java Webstart /JNLP for distributing java apps. I've never done it, but it takes all this hassle out for you by automatically maintaining dependencies. I'm intending to try to get Ensmer going using JNLP sometime.
    Dusty

  • Extension jars within a jar

    hi
    i was just wondering whether it is possible to have (download) extension jars inside a jar file so you could distribute just a single file? if it is possible how would you refer to them in the manifest?
    cheers
    andy

    why not?
    1. extract other .jar file
    2. add extracted files to your own one jar.
    distribute the last .jar file..
    The following may help you..
    JavaJar(written by java) can compress and decompress jar,war, ear and.zip...
    may download from http://www.qwerks.com/download/4114/JavaJar.zip
    the tool is very verygood tool.
    but the homepage(www.pivotonic.com) of JavaJar cannot be accessed.
    it is funny.
    good lucky.

  • Jars within Jar

    Hello All,
    I have written a custom ant task and have made a jar and placed it in Ant's lib directory. The jar file has some dependencies which are jar files them selves (jdom.jar,commons-lang.jar and javagit.jar to be exact). It also has a dependency on ant.jar but I have not included that in the application's jar file.When I execute the custom ant task, I get an error "ClassNotFoundException" for classes that are being used in the Custom Ant Task class (except for Classes in ant.jar).When I extract the dependencies and then create a jar file (no jars within the jar file), it works fine !
    Here is the METAINF file when the dependencies are extracted
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: 11.0-b15 (Sun Microsystems Inc.)
    Class-Path: . (in case of jars --> jdom.jar javagit.jar commons-lang.jar)
    1. How come I am not getting any errors for classes in ant.jar ?
    2. Can any one kindly explain why the JRE can't find the files from with in the dependencies as jar files as opposed to dependencies as extracted files ?
    3. Is there a way to create a jar file with dependencies as jar files and how to configure it so that the runtime can find the files from within the jar files ?
    Waiting for a favorable response.
    Kind Regards.

    Put the dependency jars file in to "C:\pogram Files\Jre1.6/lib/ext folder.It will load automatically during execution

  • Jar within Jar

    If I have a program that uses another Jar file can I put the jar file into the jar file of my application and will it be in the classpath because it is in the jar or how can I go about doing that?

    It is NOT possible to use an embeded jar file from classes of the outer jar file. The URLClassLoader, which is used to search .jar files, does not have the functionality to search embeded .jar files as well. Unfortanately there are two "ugly" choices. Either you unjar the jar file so that the embeded .jar files are now on disk, or you write a custom classloader that can search embeded .jar files at runtime. The first is not much different than packaging everything into a .zip file and enforcing the entire program be unzipped before it can be used. This is probably the best way to go for most cases. The latter, a custom loader, is difficult. In my plugin engine, we actually do have our custom plugin loader do this. Each .par file (Plugin ARchive, but identical to a .jar/.zip file), can embed other .jar/.zip files. Anything found in the /lib dir of the .par file is automatically handled by our custom loader code. Basically, when a .class is being looked for, it tries the main .par file /classes dir first. If it is not there, it then tries any embeded .jar/.zip file found in the /lib dir. Along the way we "index" package names so future lookups within embeded jar/zip files are much faster.
    There is a caveat to this though. Any code in an embeded jar/zip may do something like getClass().getResource(), or getClass().getClassLoader().getResource(). Problem is, getClass().getResource() should work on the embeded jar/zip file, not the outer par file. It took a bit of time, but our plugin engine is now able to read .class files out of any embeded jar/zip file, and it properly handles the getResource() call as well, looking in the embeded jar/zip if the call is made from a class inside an embeded jar/zip. This allows a plugin to package everything up into a single .par file and distribute it without it having to be unzipped.
    Why the URLClassLoader does NOT add this functionality is beyond me. It is really a bad design that you specify a manifest.mf file, class-path files in the .jar, but there is NO documentation explaining that you need the embeded jar/zip files to be unzipped to the disk for them to be used. The bit of code we did could easily be added to URLClassLoader to handle this situation and would prevent the numerous threads on this topic. Why the Sun team doesn't do this is beyond me!

  • Relationship of Jar within Jar

    I have a project that uses kxlm2.
    To this point in development I have included the source for kxml2 in my project hierarchy and compiled it along with my code, packaged it, ran/tested it, etc. Everything works.
    However, I don't want to compile KXML2; I just want to include the kxml2.jar distro in my projects JAR file and be able to use it from my classes.
    Is this as simple as including kxml2.jar in my jar or do I need to add it to the manifest? Do I need to explicitly load kxml2.jar within my app or does this happen magically?
    Can someone please put me on the path to enlightenment. In the mean time I will continue to dig through the docs.
    Thanks.

    Java's standard classloaders will not load classes from a jar that is itself within another jar.
    You can write a custom classloader to do that, or use a 3rd-party product (one is OneJar), or just use the kxml2 jar from your jar by adding a ClassPath: parameter to your jar's manifest file. Refer to Java's jar specification for information on the last option.

  • 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 tell if a class within a jar file is being accessed?

    Hello,
    I have written a web app using NetBeans 5.5 and some external libraries.
    Rome 0.9 and a Rome module georss-rome.jar.
    Everything works fine with the integrated Netbeans tomcat 5.5...
    When I try to deploy this as a war using Tomcat 5.5 standalone It will not work properly. To make things worse, I get no error.
    In my code, I instantiate a class in the georss module by doing the following:
                    GeoRSSModule geoRssModule = GeoRSSUtils.getGeoRSS(entry);
                    if(geoRssModule != null)
    ...do something;
    }I then check for null and if not null I do stuff with methods within that jar.
    Basically I pass a rss feed or a georss feed. If its a georss feed then geoRssModule would not be null.
    As I said, this works fine within integrated tomcat but does nothing (no expected action) with standalone which leads me to believe that this is a deployment/jar/classpath issue.
    To me it seems that the class GeoRSSModule is never actually instantiated, but I never get any errors or expected output.
    I set tomcat logging.properties to FINEST for all types of logging.
    Is there a way to determine if the jar is even being accessed for that class file?
    TIA!
    BTW, I dont have the module source.
    I also verified that the jars (rome.jar and georss-rome.jar) are being deployed to webapps/myapp/WEB-INF/lib
    Message was edited by:
    gforty

    GeoRSSModule geoRssModule = GeoRSSUtils.getGeoRSS(entry);Try placing logging statements before and after this statement so that you can track execution. Make sure that your code at least gets to this particular line where you instantiate the GeoRSSModule object. Then place a logging statement afterwards to see if an object was indeed created.
    What helps me in situations like this is that I also use the NetBeans attached debugger listening on your standalone Tomcat installation. This allows you to trace your execution on the server side, one line at a time, giving you a clearer understanding of program flow.

  • Invoking JAR within an EAR

    I am having trouble invoking my project which is packaged in a jar and the jar is then packaged in an ear file.
    I need to deploy this big ear file onto an AIX server. No single jar file can be deployed onto the server so I have no option but to include my batch project into the ear file, however, when I try to invoke my main within this jar (within the ear), the class can't be found! Can anyone help me with this? Thanks!

    oh also I forgot to mention that I am invoking my program via shell script.
    My script invokes the main function, so my first problem is not being able to 'see' that main function in my ear.I did, however, defined my ear file inside the classpath and used the classpath option when calling my programs. Thanks!

  • Making mysql jar run within my jar

    I have a programme which uses a mysql driver
    Now I cannot use it outside of eclipse.
    My jar looks like this
    /META_INF/MANIFEST.MF
    /com/bis/converter (Package)
    /lib/mysql.jar
    my Manifest looks like this:
    Manifest-Version: 1.0
    Name: com/bis/converter
    Main-Class: com.bis.converter.CsvPresentationWindow
    Class-Path: ./lib/mysql.jar
    what am I doing wrong. He just says class not found exception with the driver

    Ok I got it,
    first I thought, that the lib folder needs to be within the jar file!
    Now I have the lib-Folder outside the jar within my execution folder and it works!

  • Is it possible to open a Jar within Java code

    Hey
    I am just wondering if it is at all possible to get java to run a Jar within the code. So the Jar is my update to my program and I have got it downloading from my site using the java code but now i want the code to open it for the user so they don't have to double click in on. Is this possible?
    Thanks

    Sure. The java.util.jar package.
    You might want to take a look at service providers:
    http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html#Service%20Provider

  • Retrieving Jar path in the HD from within the jar?

    I have a small problem. I wrote a program which is packed in a jar file and this program is able to compile and run java files (Which I do by running javac and java processes) but the kind of files that this program compiles requires some other libraries inside the same package (In the jar file) so I am wondering how can I retrieve the jar path in the harddisk from within this jar because at the moment I ask the user where the program is and I think it is kind of ugly to ask the user where the program is from within the exact same program we are looking for.
    Hope I made myself understandable.
    Best Regards
    NooK

    Thanks for the answer. I mistakenlly ended writing a new thread (New to the forum)
    but if you would kindly look here, I have other problem now which I have been working on for a whole day.
    http://forum.java.sun.com/thread.jsp?thread=524717&forum=31&message=2514471
    Best Regards
    NooK

  • Getting a Directory within a JAR

    Hello, I've been wondering how it is possible to "get" a directory from within my JAR file. If, for example, my JAR's structure is:
    - meta-inf\manifest.mf
    - something\*.class
    - properties\*.properties
    - images\com\a.jpg
    - images\com\b.jpg
    - images\org\a.jpg
    - images\org\b.jpg
    Then, since my goal is to scan the JAR for all images recursively, and store them in a HashMap, I need to be able to recognise com as a directory, and org as well.
    With Thanks,
    laginimaineb.

    Nevermind, I found the answer already. To get a File from within the JAR I use :
    ClassLoader cldr = getClass().getClassLoader();
    URL urlToDir = cldr.getResource(directory);
    File dir = new File(urlToDir.toURI());Thanks anyway.

  • Run a jar-File and modify a file within this jar-File

    I am running the jar-File, which contains my compiled java files etc.
    The program has a config part, which is saved in xml file.
    This xml file is in the same directory like the class files.
    All theses files are zipped as jar-File.
    Well, I am running the jar file.
    - But how do I open and save the xml file ?
    - Is that possible ?
    - How difficult ist that ?

    I tried to do this some time ago and found out the hard way that you can't, just as DrClap just told you. I would have taken his work for it anyway, but for what it's worth, I thought I'd mention that you're not alone. In my case I wanted to be cute and keep my properties all together within the .jar; thought it'd be cleaner that way. Ended up just creating the more typical class_name-props file in my home directory. Is this what you had in mind?
    ~Bill

Maybe you are looking for