JARs inside my JAR

Hi Folks,
I'm creating a JAR file for my application. My app uses another JAR file and I want to package it inside my jar.
I tried to use "Path-Class" attribute in MANIFEST.MF file but without success.
Any help would be appreciate.
TIA.
Romualdo Rubens de Freitas

I wonder how you missed to recognize that jars DO contain jars for four years, as you subscribed in 2001.
Of course the standard class loader cannot handle jars in jars, but many solutions do exist for this problem. (It was really a problem, since almost all java applications are required to ship with jars inside jars).
The best solution I encountered, is the fat_jar plugin for eclipse. If you are not an eclipse user try ONEJar.
Being silent is sometimes better than to provide non-solutions for problems for which solutions exist.

Similar Messages

  • Using resources from an external JAR inside a JAR

    Hi,
    I'm trying to package all parts of my application into a JAR file so I can deploy my application using Java Web Start. However, I have an issue.
    I need to use the files from an external JAR, Ice.jar, with my application. Therefore, I included Ice.jar in my build, specifically in the lib/Ice.jar directory.
    This does not seem to be working; my application cannot read the information from the Ice.jar file when I launch my JAR file. It does work in one instance, however:
    I have a directory included in the same directory where my JAR file is. This directory is named lib, and contains Ice.jar. My directory structure is as follows:
    dist
    dist/NVAC.jar //my JAR
    dist/lib/Ice.jar //the external JARMy JAR file, NVAC.jar, will ONLY work if that lib directory is included in its directory. This is NOT what I want to do; I want to include the external JAR inside my JAR file, so a user will only have to download the JAR file. I have included the external JAR inside my JAR as I mentioned previously; at the path myJAR/lib/Ice.jar.
    Therefore, how do I use a resource from an external JAR inside my JAR? Do I have to use ClassLoader? ClassLoader.loadClass() perhaps?
    If I can provide any more information, please let me know.
    Thanks

    Seems to me it isn't practical to want to do things
    that don't work. Especially since you're using
    WebStart and it takes care of dependent jars
    automatically for you if you configure things
    correctly, so this absurd idea of jars inside jars
    isn't even helpful.Dang DrClap, you seem to be the go-to guy for destroying all my ridiculous ideas (no offense; I mean that in a good way).
    Seems I did not understand JWS fully when I thought of that idea. I researched it more after reading the replies here, and I see that I was indeed thinking absurdly.
    Thank you for the help,
    Dan

  • Referencing Jar inside a Jar

    Hi,
    i have a jar file. the classes inside the jar file refers to classes within another jar file. i packaged the second jar into my jar file but during runtime i get NoClassDefFoundError when i refer to the classes inside the second jar.
    i tried giving the classpath in manifest file but it does not work.
    My question is how to reference a jar which is inside another jar?
    Thanks
    Daniel

    I don't think you can reference classes inside a jar that's itself in a jar.
    However you can definitely reference classes in a (non-nested) separate jar.
    For example A.class in A.jar can reference B.class in B.jar if you put:
    Class-Path B.jar
    in A.jar's manifest file.
    One thing that screwed me up when I first tried this stuff, was that the syntax of Class-Path is not the same as I first expected. If you have more than one path items to put in your class path, you don't separate them with a colon or semicolon, but with spaces.
    good luck
    j

  • Referencing a jar inside another jar

    Hi All,
    If there is a jar "B" inside jar "A", how to include jar "B" in the manifest's classpath of jar "A"??
    Regards,
    P

    let me know if you figure out the answer to this question. I am working on a executible jar and I reference lib/somJar.jar on my manifest file. I thought that it was working because it was loading, but when I tried to move the jexeutible jar it no longer worked. Well I found that it was loading the information from the directory, which was teh same directory that I used to jar the files rather than the actuall jar file.

  • Jar inside a jar

    I would like to insert a jar (jar1) into another jar (jar2). I have extract all files of jar1 and then I construct jar2. But then when I click on jar2 I have the following message : "Could not find the main class".Is there something to add to the manifest? My manifest only gives the main class of jar2.

    http://forum.java.sun.com/thread.jsp?forum=22&thread=405160&tstart=0&trange=100

  • Loading jars inside jars

    I'm currently building a console launcher that automatically fetches the console UI classes from servers and then caches them to client machine. User can then launch console UIs of different kinds of servers using unified launcher.
    My problem is that most of the console UIs are dependant of other libraries and extracting these libs inside the UI jar is not an option. I've tried to package all jars including the console UI application itself into a another jar but hitting the wall currently when I try to accomplish something like this:
    1. Check if disk cache already contains the jar file with md5
    2. If not fetch the jar to disk
    3. Open the jar file
    4. Fetch all jars inside the jar and pass them to new classloader from classloaderpool <- This is where i hit the wall as I can't figure how to make the classloading of jars inside another jar.
    It seems that i can't create JarFile instances from inputstreams but only from specified filenames.
    I tried to use uberjar from codehaus but couldn't figure how to instantiate the main class of the console ui with parameters from inside another application.

    I suddenly find myself with a similar problem. My app is deployed with webstart, but I need to put a jar file in there (edtftpj-1.3.2.jar) so it can use FTP. Where do I put it? Right now it's inside a lib directory, but it's not getting found by the app that calls it.
    Help?
    --- Eric

  • Is it possible to extract out the jars in XMLConnector.jar?

    Hi all,
    I've currently got Crystal Reports working properly in my Java Web project, which is using an XML Datasource if I include XMLConnector.jar in my WEB-INF/lib folder. However, we don't want to have to include this rather large jar in our project as it contains many jars that we already have.
    I tried to extract out the jars inside XMLConnector.jar into my WEB-INF/lib folder, but now I get the same exception as if I had not included XMLConnector.jar:
    com.crystaldecisions.reports.common.QueryEngineException: Error loading database connector. The class 'com.crystaldecisions.reports.queryengine.driverImpl.DriverLoader' could not be accessed.
    Caused by: com.businessobjects.reports.jdbinterface.common.DBException: Failed to load the database connector 'crdb_xml.dll'.
    Is there a way to diassociate the contents inside this jar, or if you can help me locate the exact libraries that are required to properly load XML datasources, and any settings I need to change.
    Thanks,
    Peter

    The XMLConnector.jar is a jar of jars.
    There are some Java Web Application Servers that have issues with unjarring jar of jars for the jars within.
    So for those deployments, I do recommend unjarring XMLConnector.jar.
    For a Web App, you'd put the jars in the jar in the WEB-INF/lib folder, and other content within WEB-INF/classes. This because there's no special handling of a jar of jars - the CRJ engine merely asks the classloader to handle the loading.
    Sincerely,
    Ted Ueda

  • 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.

  • How to make an applet to read the Text file present inside a jar

    Hi All,
    I have writen one applet named ReadFile.java which reads a text file present in the same directory and does some manipulation of text file contents.
    The applet code runs successfully when i run the applet in command prompt like
    {color:#ff0000}*java ReadFile*{color}
    And i am getting the needed results.
    Then i made a jar file with the applet code and text file as
    {color:#ff0000}*jar cvf rf.jar ReadFile.class File1.txt*{color}
    Then i have inlcuded this applet inside a html file as
    {color:#ff0000}*<applet code= "ReadFile.class" width= "500" height= "300" archive = "rf.jar" ></applet>*{color}
    after this when i load the html file, the applet code is not executed fully. Its throwing FileNotFoundException: File1.txt.
    Applet is not recognizing trhe text file present inside the jar file.
    Can any body explain me how to overcome this problem. Any setting needs to be done for making the applet indicate the presence of Text file inside the jar file.

    what code in your applet gets the text file and reads it? are you using getResource or something similar?

  • How can i get the path to config folder placed inside the jar file?

    Hi i have developed an RCP application using eclipse.
    In my application config directory is there.
    When i export my RCP application as JNLP Project the jar file is created which contains config folder inside it.
    When i download the application using java web start , how can i get the path to config folder placed inside the jar file?
    Will the config folder exists in local cache in my system?
    Help needed.
    -Deepak

    -- This works in CS6:
    tell application "Adobe InDesign CS6"
      set myDocument to active document
      set selectedRectangles to selection of myDocument
      set theGraphicsLink to file path of item link of (graphic 1 of (item 1 of selectedRectangles))
    --> "Macintosh HD:folder/folder/filename.tif"
    end tell

  • JRE doesn't find the main class inside a JAR archive file

    Hello everybody,
    I've written a small application in Java, using NetBeans. Running my application inside NetBeans works fine, but I can't run it from the console or by double clicking the jar file.
    Running it from the console I get the following error message:
    java -jar TestApplication.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: tst.Benchmark
       at gnu.java.lang.MainThread.run(libgcj.so.81)
    Caused by: java.lang.ClassNotFoundException: tst.Benchmark not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:TestApplication.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
       at java.net.URLClassLoader.findClass(libgcj.so.81)
       at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.81)
       at java.lang.ClassLoader.loadClass(libgcj.so.81)
       at java.lang.ClassLoader.loadClass(libgcj.so.81)
       at gnu.java.lang.MainThread.run(libgcj.so.81)I know that these errors often come when the class path is not set in the right way, and using a single java file, you can fix this by passing the parameter "-cp ."
    I tried this with the jar file but it does not work and using "-cp TestApplication.jar tst/Benchmark" didn't work either.
    Inside the jar file I have the META-INF Folder and a "tst" Folder which contains all my class files. And I've set tst.Benchmark as the main class, this also stands in the manifest file correctly.
    Do you have any ideas what could be wrong?
    Greetings JavanianGuy

    This line
    at gnu.java.lang.MainThread.run(libgcj.so.81)says that you're using GNU's Java, not Sun's Java. They are not the same. GNU Java is incomplete.
    You'll need to ask this question at the GNU Java site.
    Recommendation: Use Sun's Java

  • Running a batch file inside a jar

    HI all
    I created a jar file , in which i need to run a batch file , so i wrote a main class to execute the run the batch file , but when iam running the jar it is searching for the given batch file out side the jar.
    my code is some thing like below
         public static void main(String args[])
              try
                   Runtime rt=Runtime.getRuntime();
                   Process process=rt.exec("%DIRNAME%/start.bat");
       InputStreamReader reader =
                      new InputStreamReader ( process.getInputStream () );
                   BufferedReader buf_reader =
                       new BufferedReader (  reader );
                    String line;
                    while ((line = buf_reader.readLine ()) != null)
                                 System.out.println (line);
              catch (IOException e) {
                    System.out.println (e);
         }so please help me.. is it the problem in specifing the path...?
    are does it have any other method to read the stream functions ..
    thanks in advance
    sam

    I don't think this will work. You could not go to a command line and enter, "%DIRNAME%/start.bat" if start.bat was inside a jar - the CLI doesn't know how to read a batch file inside a jar.
    I think it would work to programmatically read the lines of start.bat (when it is inside the jar) into an array of Strings and use Runtime.exec with the array as the argument.
    It would also work to extract the start.bat file, then execute it using Runtime.exec.

  • Call class inside a jar file??

    Hello group,
    I have a class with a main mathod and this class is inside a .jar file. This jar file reside under my
    web-inf\lib or class-path directory in my application at Weblogic Server.
    How can I call this class by command line?
    I have to create a cliente to do it?
    Is it possible? I´m having problems because the weblogic server is using the jar file at the same time that I trying use it calling by command line.
    Where can I find more information?
    Message was edited by:
    Denimar

    Authcloud9981 wrote:
    Hi I have an executible JAR file that I can call from command line by using the command - "java -jar file.jar".
    Is there a way for me to call this JAR file inside a Java class in another Java Program?There can be more going on in a jar than just as a container for classes.
    The manifest defines the behavior. So to replicate the behavior you must do exactly that.
    As an example of that.
    [http://java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html#download]
    Additionally by running it in your application you must consider what the scope of that is. If you just load the classes directly then they will be in the system class loader and thus cannot be unloaded. Using a class loader solves that.

  • Include and call an .exe file inside my jar file

    Hi.
    I want to include an exe file and call it inside my jar file. this is the code.
    InputStream is = getClass().getResourceAsStream("/native/my.exe");
              int[] line = new int[is.available()];
              File myFile = File.createTempFile("my","exe");
              myFile.deleteOnExit();
              myFile.setExecutable(true);
              FileOutputStream out = new FileOutputStream(myFile.getAbsolutePath());
              int i = 0;
              int c;
              while((c=is.read()) != -1){
                   line=c;
                   i++;
              is.close();
              for(int j= 0;j<line.length;j++)
                   out.write(line[j]);
              out.close();
    So i store it in my temp folder. Than i run
    String myFileLocation = myFile.getAbsolutePath();
    p = rt.exec(myFileLocation);
    Everything goes fine, but the behaviour of the .exe file is not the same. I mean when i run the commands
    PrintWriter writer = new PrintWriter(p.getoutputStream());
    writer.println("command");
    the behaviour is not the same. What goes wrong.

    But to load the xml file I need to create a File objectIf this is true then you will not be able to load the XML file, since a jar entry is not a File object and cannot be represented as one.
    However if you get rid of whatever it is that loads your XML file and replace it by more standard JAXP processing, you should be able to parse an InputStream that reads from the jar entry. You know how to get that so it should not be a problem.

  • 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

Maybe you are looking for

  • ICal: january has dissapear!!!!!!

    The month of janury has dissapear from iCal in both my wife's macbook and my macbook pro (which are not sincronize). The main window and the preview window would jump from dec 2007 to february 2008. I can only get to jan 08 if i change my view to wee

  • CS6: Can't switch off color management in the printerdriver when photoshop manages colors

    So this is weird: I'm using CS6 Extended and Lightroom 5 on a Windows 7 Pro machine, printing to an old Canon Pixma Ip5200R. When i print from Lightroom, i am using a special printer profile for the pixma and my photopaper, so color management is swi

  • Dv6-1216sa cpu upgrades?

    running win 7 32bit, (although will be upgradeing to 64bit soon) bios up to date F:18 current cpu: AMD Turion X2 RM-74 2.2GHz currently my ram is 4gb, which i can only use 3 of hence the upgrade to the 64 bit os soon i will be upgradeing to 8gb ram,

  • Sample Rulebase in OPA 10.4.2 - Error 404 -- Not Found

    Hi, I just installed OPA 10.4.2 but was not able to load the sample rulebases included in the package. I simply copied all compiled rulebases (*.zip) from C:\V35235-01\examples\rulebases\compiled to C:\OPA\web-determinations\web-determinations\WEB-IN

  • Documentation for Custom Disposition Action services in URM

    In 11g URM, the documentation references the ability to create a custom disposition action by accessing one of the pre-defined services and passing parameters. Unfortunately I can not find documentation stating what the parameters are for each of the