Including a jar file inside an executable jar file

Is it possible to include a jar file inside another (executable) jar file such that the included file is part of the class path for the outer file? If so, how do you specify this in the classpath in the manifest?

Russ_Bjork wrote:
Is it possible to include a jar file inside another (executable) jar file such that the included file is part of the class path for the outer file?No. Actually, I suppose it would be possible if you do all the 'heavy lifting', but Java is not designed to handle Jars within Jars.
What do you see as the advantage of doing that?
Is your app. a rich client (e.g. Swing, AWT, SWT..)?
Can you distribute the app. from a server or the internet?

Similar Messages

  • Updating an XML file inside the executable JAR.

    Hello all!
    I would like to askk how can i update an XML file that is packaged inside my jar file?
    For intstance:
    I have a Java Application in NetBeans
    Inside a package i have constructed a custom .xml file.
    I can read from this file using
    .....getClass().getResourceAsStream("/.../file.xml")and after that using XPath for querying and works fine.
    I want to update an entry in my xml file so the jar contains now the newly updated file.
    Thanks everyone who spends hit time to read this. Hope someone can help me.

    Please don't cross-post:
    http://forums.sun.com/thread.jspa?threadID=5342194

  • How do i wrap a dll inside an executable jar

    hi,
    i have an executable jar that uses jni to reference native code in a dll.
    i can launch the executable jar only if the dll is in the same directory as the jar (or in system32).
    so, i figured if i added the dll to the jar it would work. no!
    what do i do to deploy only 1 executable jar?
    thanks

    Hi anonimuds,
    I see useless “expert” activities here instead of giving a real response!
    You can pack a native library with bytecode if you use WebStart technology. Let look at the example tested by me. It shows Windows MessageBox from the native method.
    Here is Java class HellowWorld:
    package test;
    public class HellowWorld {
    static {
    System.loadLibrary("HellowWorld");
    public static void main(String[] args) {
    DoHellow();
    public static native void DoHellow();
    }With javah I generated C++ header:
    /* DO NOT EDIT THIS FILE - it is machine generated */*
    *#include <jni.h>*
    */* Header for class test_HellowWorld */*
    *#ifndef _Included_test_HellowWorld*
    *#define _Included_test_HellowWorld*
    *#ifdef __cplusplus*
    *extern "C" {*
    *#endif*
    * Class: test_HellowWorld
    * Method: DoHellow
    * Signature: ()V
    JNIEXPORT void JNICALL Java_test_HellowWorld_DoHellow
    (JNIEnv *, jclass);
    #ifdef __cplusplus
    #endif
    #endifWith MS Visual Studio I made a simple library with the native method implementation:
    #include "stdafx.h"
    #include "test_HellowWorld.h"
    BOOL APIENTRY DllMain( HANDLE hModule,
    DWORD ul_reason_for_call,
    LPVOID lpReserved
    return TRUE;
    JNIEXPORT void JNICALL Java_test_HellowWorld_DoHellow(JNIEnv *, jclass)
    MessageBox(0, "Hellow World!", "Message", MB_OK);
    }I compiled Java code above to test.HellowWorld.class and JNI code to HellowWorld.dll.
    Then I packed bytecode and DLL to HellowWorld.jar with batch file:
    %java_home%\bin\jar cvmf MANIFEST.MF HellowWorld.jar test/HellowWorld.class ./HellowWorld.dll
    %java_home%\bin\keytool -genkey -v -alias vitaly -keystore OlejaKeystore -storepass MyStore -keypass Caretta
    %java_home%\bin\jarsigner -keystore OlejaKeystore -storepass MyStore -keypass Caretta HellowWorld.jar vitallyWhere content of MANIFEST.MF is
    Manifest-Version: 1.0
    Created-By: 1.4.2_12 (Sun Microsystems Inc.)
    Main-Class: test.HelloWorldBefore deploying the project to Intranet Site I prepared JNLP and HTML files.
    The content of HellowWorld.jnlp file is
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" codebase="http://vitallis/HellowWorld">
    <information>
    <title>HellowWorld Example</title>
    <vendor>ABC Ltd</vendor>
    <homepage href="HellowWorld.html"/>
    <description>JNI Test</description>
    <description kind="short">JNI Test</description>
    </information>
    <security>
    <all-permissions/>
    </security>
    <resources>
    <j2se version="1.3+" href="http://java.sun.com/products/autodl/j2se"/>
    <j2se version="1.3+"/>
    <jar href="HellowWorld.jar" main="true" download="eager"/>
    </resources>
    <resources os="Windows">
    <nativelib href="HellowWorld.jar" download="eager"/>
    </resources>
    <application-desc main-class="test.HellowWorld"/>
    </jnlp>The codebase value you will change to URL of your Site. And at the last, here is HellowWorld.html text
    <html>
    <head>
    <title>Java Web Start Example</title>
    </head>
    <body>
    <P>Java Web Start Example:</P>
    <P>
    <a href="HellowWorld.jnlp">JNI Example</a>
    </body>
    </html>I have tested this project on my computer and it runs fine.

  • How can I add image files to a executable jar file ?

    Could you tell me how can I add image files to executable jar file ?
    package structure:
    ../com/Main.class
    ../images/..

    Please don't cross post, and read this
    http://forum.java.sun.com/thread.jsp?forum=31&thread=271751
    I've answered the question in the New To Java thread.

  • JAR to EXE or executable JAR conversion

    Greetings all
    I have a jar file placed in my java\bin folder. i want to make it into an executable .exe file. if not that i want to execute it without going on command line and writing
    java -jar MyJar.jar
    is there any solution?
    somebody told me to make a .BAT file and run it..i dont know anything about BAT files...is there any convertor that may convert my Jar into .EXE file keeping icons + images in my program intact?

    rabia409 wrote:
    Greetings all
    I have a jar file placed in my java\bin folder.Why? It should not be there?
    i want to make it into an executable .exe file.Please forget that for a moment and tell us what your goal is (instead of what you think the correct approach is).
    if not that i want to execute it without going on command line and writing
    java -jar MyJar.jarSo you want to double-click it and it should run?
    If your system is set up correctly and "java -jar MyJar.jar" works, then double-clicking it should start it was well.

  • How to restore a file inside an encrypted sparsebundle file saved in time machine

    Hi,
    On Mac OS X 10.6.6, I use an encrypted sparsebundle file to save sensitive corporate files (not using the Filevault built-in feature), mounting it and using it as a folder.
    The sparse bundle is in my Documents folder which is part of my Time Machine backup.
    Unfortunately, timemachine doesn't actually see what's inside the sparsebundle file and can't restore only one of the files from it.
    I always have to restore the full sparsebundle, which is 34G as of now...
    Is there a way to let timemachine index and store the content of the encrypted sparsebundle, without compromising the confidentiality of course?
    What other completely different solution should I use otherwise?
    Thanks.

    mimizone wrote:
    everytime it says it can't be mounted the reason being "no mountable filesystem"
    the file size reported by the Finder is blank, which I am not sure is related.
    Not a good sign.  That's the message OSX sends when a disk image is corrupted.    Can you restore the whole thing, and still see the contents?
    It seems an external drive or partitioning the drive would be required, unless using sparsebundle files would do the same.
    A separate drive or partition, each with different passwords, would probably work.
    side question, it seems TM saved the entire modified files and not only the modified blocks. Does it behave the same for sparsebundles? it doesn't seem to copy my 34G file everytime.
    Do you have a "sparse disk image" or a "sparse bundle disk image"?   As I understand it, Time Machine saves the entire contents of a sparse disk image if anything's changed, but only the modified "bands" of a sparse bundle disk image (but only when they're not mounted). 
    If you use an encrypted HD or partition, it should work normally -- just saving the individual files that are changed, and allowing you to view and restore individual items.

  • How can I put files inside an empty .zip file with Mac OS X?

    Hi all,
    I'm learning to produce epub files (i.e., ebooks). I'm told by tutorials that I need to zip several files together, but I must start from a specific file and put that file first into the .zip archive… then the others.
    I can't find ways to put files one after another inside a .zip archive using Mac. Anyone can help?
    Thanks in advance,
    lux

    Donald Palmer wrote:
    Create a folder.
    select file to zip.
    right click on file.
    choose compress.
    put resulting file in newly created folder.
    No, first file must stay uncompressed until the final zipping occurs.
    I found the answer by browsing around. There is a nice AppleScript called ePub Zip (http://www.mobileread.com/forums/showthread.php?t=55681) that just works.
    I read around that it can be done via Terminal with two commands:
    +zip -X0 "full path to new epub file" mimetype+
    and
    +zip -rDX9 "full path to new epub file" * -x "*.DS_Store" -x mimetype+
    I didn't check it though.
    Thanks for the support,
    lux

  • How can i include .so files in an executable .jar?

    Hi,
    I need to some native libraries to run my app. I want to put this .so files into a jar file.
    With a shellscript i can set the java classpath, but i need to have only the jar file. If anybody know what do i do to java search the files into a directory specified by me (a directory compressed into the jar file) please help me!
    Any help is wellcome.
    Thanks. Bruno.

    http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/faq.html#210
    http://java.sun.com/products/javawebstart/download-spec.html
    You create a jar file containing JUST the native resources (i.e. the .so file).
    You add a <nativelib > element to the JWS file wrapped in a "<resource os="linux" arch="x86">" tag (I think, not done in some time, check the links above).

  • Opening a file with any executable .exe files

    plz tell me if u have ne idea abt the opening any given file or the information contained in it with
    another application i.e .exe file for example the text document has to be opened with a textpad..
    it is very urgent..plz
    neha

    See if this is useful.
    what made you ask this question in Swing Forum ?
    Process P=Runtime.getRuntime().exec("notepad "+"C:\\A.txt");        
    //Process P=Runtime.getRuntime().exec("D:\\j2sdk1.4.2_05\\bin\\javac.exe  "+"Demo.java");
    InputStream err = P.getErrorStream();
    InputStreamReader in = new InputStreamReader(err);
    BufferedReader buff = new BufferedReader(in);
    String line = null;
    while ( (line = buff.readLine()) != null)
    System.out.println(line);
    int exitVal = P.waitFor();
    System.out.println("Process exitValue: " + exitVal);

  • Cannot make executable jar file for swt application

    hi to all!!! i have started learning swt library and it seems nice to me, but i have one problem, i cannot run my application. The problem is that i cannot make executable jar for it.
    i'm using ecilpse_3.1.2 and have pluggined the visual editor for swt! yesterday i found one topic where was described the process of making the swt executable jar, i followed the instructions in the topic, but didn't resolve my problem, so if anybody knows how to achieve this , please help!!!!!!
    the instructions in the mentioned topic are :
    1. Make sure the SWT jar file is included in the Eclipse project build path
    a. Download the standalone SWT jar file from eclipse.org even if you already have the ones that come with Eclipse. It is called ?swt.jar? and you will package it with the executable JAR. Make sure it is the same version of SWT that you used to make your program.
    b. In Eclipse, import swt.jar via Project Properties::Java Build Path::Libraries::Add External JARs. (Make sure to include the source .zip file). Also make sure to select the swt package in the ?Order and Export? tab.
    c. At this point, you should be able to compile and run your SWT application in the Eclipse SDK.
    2. Do a standard Eclipse jar file export
    a. Right click on the main .java project file and select ?Export??.
    b. Choose ?JAR File? from the list.
    c. Select the relevant packages and .classpath and .project resource files
    d. Make sure ?Export generated class files and resources? is selected and browse to the location where you want the JAR file to be created.
    e. Specify ?Generate the manifest file? and don?t seal the JAR or any packages. Choose the class containing the main method as the ?Main class?.
    3. Change the manifest file
    a. Navigate to the JAR file you created and open it with WinZip.
    b. Open the MANIFEST.MF file inside and copy the contents.
    c. Create a new file called ?MANIFEST.MF? and paste in the contents of the old manifest file.
    d. Add the line ?Class-Path: <swt jar file path>?. For simplicity, you can just keep a copy of the swt.jar file in the same folder as the executable jar, in which case, the line is ?Class-Path: swt.jar?. Make sure there is a carriage return after the last line in the manifest file, or that line will not be parsed.
    4. Replace the manifest file
    a. Make sure the manifest file and the executable jar are in the same folder.
    b. Open the command prompt and navigate to the containing folder.
    c. Enter the command ?jar umf MANIFEST.MF <executable jar name>? to update the manifest file with the class path information.
    5. Package the JAR with SWT files
    a. Put the updated executable JAR file, swt.jar, and the associate DLL in the same folder. The DLL can be pulled out of swt.jar and should have a name like ?swt-win32-####.dll? on Windows.
    b. The JAR file should now successfully execute. On Windows, you can usually just double click the JAR file in explorer and it will open. If that does not work, the command ?java ?jar <executable jar name>? on the command line has the same effect.
    but a few steps aren't exact for me , for example : first, which jar i have to include in build path : downloaded or from plugins folder, second
    i have to incude source.zip too??? but it is only in downloaded zip file which includes both swt.jar and src.zip, and finally can anyone clarify next :
    "5. Package the JAR with SWT files
    a. Put the updated executable JAR file, swt.jar, and the associate DLL in the same folder. The DLL can be pulled out of swt.jar and should have a name like ?swt-win32-####.dll? on Windows."
    what does this mean, put these in folder or make jar from them????

    wolve634 wrote:
    but a few steps aren't exact for me , for example : first, which jar i have to include in build path : downloaded or from plugins folder, secondTry it both ways. If neither works, then ask again. In a suitable forum, though. An Eclipse forum or an SWT forum or something related to where you got those instructions would make a lot more sense than asking here.
    i have to incude source.zip too???No, of course you don't have to distribute the source code.
    a. Put the updated executable JAR file, swt.jar, and the associate DLL in the same folder. The DLL can be pulled out of swt.jar and should have a name like ?swt-win32-####.dll? on Windows."
    what does this mean, put these in folder or make jar from them????It says "Put (them) in the same folder". You're asking whether that means to put them in a folder? Yes, it does.

  • Opening html files inside jar

    Hi,
    I'm making a program where i have a set of help files in the form of html and i would like to open them when the user clicks the "Help" button and I used this code at first
    try
         Desktop.getDesktop().browse(new URI("resources/html/help.html"));
    catch (Exception ex)
         JOptionPane.showMessageDialog(null, "Could not open help.html in default browser\n", "Error", JOptionPane.ERROR_MESSAGE);
    }However after I made the jar and tried to execute on another computer however, it wouldn't work and would display the error message. I was wondering if there was some way that I could open the help.html in their default browser, or maybe a frame if that works, from the jar and have my program still be platform independent?

    ok so i just realized that it doesn't make sense for a program outside the jar, like IE or Firefox, to be able to access and open a file inside of the jar. I am now looking for suggestions on how to work around this problem for my program to be able to have a simple help system located inside the jar that can be loaded during runtime.
    Thanks for your suggestions.

  • Executable jar files and manifest file

    Hi,
    I have the following files in a folder named: Test
    a.jar
    b.jar
    c.jar
    Driver.class
    Driver.mf
    Here, MainClass is the main executable class that uses a,band c.jar files. This is how my MainClass.mf file looks:
    Manifest-Version: 1.0
    Main-Class: Driver
    Class-Path: a.jar b.jar c.jar
    Now I use the following command to make one executable jar file:
    jar cmf Driver.mf DriverMain.jar *
    It creates an executable jar file named : DriverMain.jar
    Now I copy the executable jar file (DriverMain.jar) into a different folder named: RunTest
    and double click it, doesn't work.
    my question is:
    what am I doing wrong? Any special characters needed in my Driver.mf file (space/newline/etc)?
    What I am trying to get is: One execuatble jar file so I can just double click to run it, and that single executable jar file will have all the necessary jars in it (i.e. a.jar, b.jar, c.jar in this case)
    Anyone please help!
    Thanks
    -Ron

    Rony,
    Sorry to disappoint, but you can not use embeded jar/zip files within an executable jar. The JDK sadly for some reason decided this was not a useful idea, so developers like me who want to distribute plugins with thier own dependencies have one of two choices. You either have to unzip the jar file that contains the embeded jars to a directory, then run your primary exectuable jar, OR you have to write a custom classloader that your "launcher" creates then loads the embeded jar files.
    The best thing to do is either jar up a, b, c and driver into one jar, so that it works, if you can legally do this. A lot of 3rd party libraries may not allow this per their license. Otherwise, another choice is to use a free installer or buy an installer that allows you to distribute a single exectuable installer program that will properly create the dir structure you need.
    As for the way it works, if you declare:
    Class-Path: a.jar b.jar c.jar
    the JAR loader code in the JDK looks in the root dir where your application was started for a/b/c jar files. They have to be on disk.
    If you want to place them in /lib, for example, you would havd a jar file like:
    Driver.class
    Driver.mf
    lib/a.jar
    lib/b.jar
    lib/c.jar
    When unzipped, your "root" dir would look exactly like the above, and your manifest would have Class-Path using ./lib/a.jar ./lib/b.jar ./lib/c.jar
    Anyway, there thus far isn't any way around this issue of embeding jar files in an executable jar file. You MIGHT be able to not specify any classpath, then in your Driver.class, create a new custom classloader that dervies from URLClassLoader, but in the findClass(), you get a ref to the .jar file that the classloader class is inside of, and from that use it to find the lib/*.jar files and add them to the classpath. For this to work, however, your Driver.class code should ALSO be contained in an embeded jar file that is loaded by this custom loader. The only thing Driver.class would contain (and I would rename it to something like Launcher) is the code to create the custom classloader.
    It's fun stuff, but a little bit of work to make it work. You can infact make it work! I may yet one day take our plugin engine custom loader and create a way for this to work!

  • Why -jar option used to install a software which is in executable jar file?

    Hi all,
    i have a query, i have a generic installer which is used to install the oracle weblogic 10.3 software in unix platform(i.e., which is in .jar extension) which is executable jar file.
    To install this software which have to use -jar option to install
    java -jar net_server<version>_generic.jar
    my question that why we use -jar option to install or to extract the software
    can any one clarify my doubt...
    thanks in advance
    abhi
    Edited by: sumanth_abhi on Jan 27, 2009 11:50 PM

    According to the Jar Guide (http://java.sun.com/j2se/1.4.2/docs/guide/jar/jarGuide.html)
    Executable Jar Files
    On Microsoft Windows systems, the Java 2 Runtime Environment's installation program will register a default association for Jar files so that double-clicking a Jar file on the desktop will automatically run it with javaw -jar. Dependent extensions bundled with the application will also be loaded automatically. This feature makes the end-user runtime environment easier to use on Microsoft Windows systems.
    The Solaris 2.6 kernel has already been extended to recognize the special "magic" number that identifies a Jar file, and to invoke java -jar on such a Jar file as if it were a native Solaris executable. A application packaged in a Jar file can thus be executed directly from the command line or by clicking an icon on the CDE desktop.
    Despite that every JAR file can be executed as a program if and only if the META-INF/Manifest.mf contains the Main-Class tag. This done through java -jar jarfile.jar
    --olaf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Input to an executable jar from a batch file

    Hi, I have created an executable jar program to receive the input during runtime from a batch file. I have tried to run the program by passing arguments at runtime but the code doesn't seem to execute. Can anyone help me out to pass an argument to the java program using the batch file. The flow of my project is -> The batch file triggers the executable jar file (I am able to execute till this !) -> The input to the executable jar file should be fetched from the arguments given in the batch file which will be taken as the input for the java program.

    My java code prompts the user to enter the data but the batch file when executed executes the code but does not wait for the user input. This is the message my batch file displays when executed.
    C:\Users\Administrator\Downloads\BatchTool>java -Xms512M -Xmx512M -jar Program.jar -o true
    Enter custom directory :
    C:\Users\Administrator\Downloads\BatchTool>PAUSE
    Press any key to continue . . .
    If I press any key the program exits
    Is there an option to give the input via batch code ? My doubt is not in the java code. Its the batch file which triggers the code and i want the batch command which will trigger the input to the code being executed.
    Is there a way to give the input to this batch file ?
    C:\Users\Administrator\Downloads\BatchTool>java -Xms512M -Xmx512M -jar Program.jar -o true * Can i replace this code with an input for the java code ? *
    Edited by: Raja Pandian C on Dec 21, 2012 2:26 PM
    Edited by: Raja Pandian C on Dec 21, 2012 2:27 PM

  • FileWriter in executable jar

    I have a problem to read/write textfiles inside an executable jar.
    The problem exists when the files are included in the jar.
    E.g. writing to files outside the jar is fine and currently my solution is to keep them that way.
    At first I also had a problem pointing to images in the
    jar-file but it worked with something like the following:
    img=java.awt.Toolkit.getDefaultToolkit().getImage(getClass().getResource("example.gif"));
    I tried the same approach to the FileReader like this:
    FileReader fr=new FileReader(getClass().getResource("example.dat").toString());
    The application compiles fine but does not find the file.
    Please share your expertise with me.

    You have to use external files or play with the java.util.jar package - there is not support for writing things directly to a jar in the java.io package.

Maybe you are looking for

  • Item Category not Defined Error message when deleting a batch item in Deliv

    Hi, I am trying with a Intercompany transfer . So after creating Interco. Transfer we have followed with a delivery document. Now,we would like to delete the delivery document. For your info. Del. doc is still open. We haven't gone for Goods issue or

  • Can't print to Xerox copier, OK from other computers

    I have recently set up our iMac next to our Xerox copier. I have dowloaded and installed the printer driver (and restarted), made whatever configurations to it were necessary, but I cannot print from any application, with one exception: i can print f

  • How to know if a specific InfoObject is being used in any Query

    Dear SDN members, I have an InfoObject which is being used for one of the InfoCube. This specific Infocube has more than 100 queries created. Is there any way I can find out if above mentioned Info Object is being used anywhere in one of those querie

  • IMPORT FROM MEMORY in job submitted program

    Hi experts, In a method I do:       SUBMIT zemr0044 USER sy-uname                      VIA JOB lc_jobname                      NUMBER lv_jobcount                      AND RETURN. Before this submit I have done:   IMPORT ls_header = ls_header FROM DAT

  • Screen blurry and shifts at horizontal halfway point when mouse moves??

    i thought my glasses were dirty today... but after cleaning them i realize my screen is slightly blurred. it seems to only effect one half of the screen at any given moment and depends on the location of my mouse pointer. if it is in the top half of