Create jar with particular path

I create a jar file using the API (package java.util.jar).
My application works fine but it creates a jar and save this path (an example):
fileA - c:\dir1\dir2\fileA
fileB - c:\dir1\dir2\dirA\fileB
How can I create a jar file and save this path ?
fileA - fileA
fileB - dirA\fileB
Thanks in advance and sorry for my english.
Matteo

Alright, this package is not documented very well, so here's the help you need.
The Zip entry, "ZipEntry" really doesn't care about the path like the file structure does. It just treats the path like a name, and when extracted with a program like unzip, the extractor creates the directories specified by the names, which are paths. You should always use relative paths in a zip archieve, and most programs will transform absolute path names just because it's dangerous.
So here is a simple method that can zip up and directory tree, and take a base path off the start of the tree. In your example the arguments to this method would be...
("c:\\dir1\\dir2", new File("c:\\dir1\\dir2"), out)
In this case the base and file are the same, because you didn't want any header directories. "out" is a ZipOutputStream that you created.... There is one problem though. I was a bad kid when I made this method, and it doesn't work on windows... so you're gona have to fix that before you can use it :)
   * Writes out all directories and contents of the given file
   * and all its decendents to the ZipOutputStream. Because it
   * it is unsafe and somewhat incorrect to use absolute paths
   * in ZipEnties, the base parameter must be non-null, have
   * length > 0 and start with a File.separator.
   * @param base The path to 'subtract' off the full path for
   * each file. For instance, if a file path is
   * "/home/joe/lovenotes/kelly.txt" and the base is "/home/joe"
   * Then the file would be placed under a ZipEntry of "lovenotes/kelly.txt"
   * @param file The file to start at. If it is a file, then it will be
   * the only entry written to the stream, otherwise, it will be recursed.
   * @param out The ZipOutputStream to write to.
   * @throws IOException if an underling IOException occurs, or if
   * a base condition is not met, such as the base not being the first part
   * of the file path.
  static private void writeTree(String base, File file, ZipOutputStream out)
    throws IOException {
    if(base == null || (!file.getCanonicalPath().startsWith(base))) {
      throw new IOException("parameter 'base' incorrect: '" + base);
    if(file.isFile()) {
      String path = file.getCanonicalPath();
      base = (base.endsWith(File.separator))
        ? base.substring(0, base.length() - 1) : base;
      // An Extra +1 so the path DOES NOT have a leading separator
      path = path.substring(base.length() + 1, path.length());
      if(DEBUG > 2)
        System.out.println(path);
      ZipEntry ze = new ZipEntry(path);
      ze.setSize(file.length());
      ze.setTime(file.lastModified());
      out.putNextEntry(ze);
      writeOutBuffer(createBufferFromFile(file), out);
      out.closeEntry();
    } else {
      File[] files = file.listFiles();
      for(int i = 0; i < files.length; i++) {
        writeTree(base, files, out);

Similar Messages

  • Creating Variable with Replacement Path to get value from ANOTHER Variable

    Hi all,
        Is anyone has created the Variable with Replacement Path to get the value from another User Entry Variable, PLEASE ? 
    First created the User Entry Variable (ZV_X) and it accepts the date range like '01/01/2009 - 01/31/2009'. Next created the Characteristic variable (ZV_Y) of Replacement Path for which source variable will be ZV_X and we should get the 'FROM Date' (01/01/2009) from the selection (ZV_X) into it (ZV_Y).
    While creating the Characteristic variable (ZV_Y) of Replacement Path, I didn't find my newly created ZV_X variable in the list of available variables under 'Variable' header in 'Replacement Path' tab and it is causing the error 'Source to replace variable ZV_Y is not defined'. How could I create the Characteristic variable of Replacement Path for my requirement, PLEASE ?
    The following is from help.sap..com:
    Replace with Characteristic Value
    Text and formula variables with the processing type Replacement Path can be replaced with a corresponding characteristic value. In the variable editor, on the General tab page, you specify under Reference Characteristic the characteristic that is to be referenced by the replacement. On the Replacement Path tab page, you can choose whether the variable is replaced with the From or the To Value and with the Key or the Name of the characteristic value. You can also specify the Offset Start and Offset Length for the output.
    Replace with Variable
    Characteristic value variables, hierarchy variables, text variables, and formula variables with the Replacement Path processing type can take their values from a different variable.
    The following prerequisites need to be fulfilled:
    Variable
    ●      The variable must not be input-ready
    ●      The variable must represent a single value
    Source Variable
    ●      The source variable must not be a hierarchy node variable
    ●      The source variable must be input-ready
    ●      The source variable must be available in the query
    ●      The source variable must represent a single value or an interval
    In the variable editor, on the Replacement Path tab page, you specify the source variable from which the value is to be determined. The value is either determined from the key, the external attribute of the key, the description, or the attribute value. You can specify an Offset Start and an Offset Length for the output here. The variable is replaced on the variable screen upon each data release.
    Thanks,
    Venkat.

    Hi Eve,
    It is possible to connect the 2 queries using a Replacement Path characteristic variable. You would need to create the variable on the char whose values you want to pass from Q1 to Q2. The variable will be of type replacement path and you will need to enter the name of Q1 from which it will get the values. Make sure that you include this char in the query definition of Q1 and Q2. In Q2 you will restrict the characteristic using this variable. DO not use this variable (replacement path) in Q1.
    In your query properties check if you have turned on the checkmark for Release for OLE DB for OLAP (3rd tab). If the check mark is there, then remove it.
    We are using the scenario in a couple of places, and it works very well.
    Hope this helps...

  • How to compile and creat JAR with native function

    Hi there,
    I wrote some native function for J2ME. But it seems like using J2ME wireless Toolkits, we can not compile native function. Is it right?
    Is anyone knowing how to compile and make JAR with J2MEWTK or command line?
    Thanks,
    Merry Christmas!!

    [zack327],
    JNI like or native interfaces APIs is not supported in the CLDC/MID Profile 1.0 specification. If you have J2ME code that includes JNI code, the J2MEWTK tool will not compile successfully for you.
    To package the compiled code to a MIDlet suite .jar file, use the 'Package' command in the J2MEWTK toolkit. It is found on the top menu bar 'Project' option as item on the dropdown list.
    To package the MIDlets into a MIDlet suite .jar file from the command line, you can execute the usual jar file command:
    jar cf MyMIDletSuite.jar Midlet.class
    You will also need to create a MIDlet .jad Application Descriptor file as well.
    HTH.
    Allen Lai
    Developer Technical Support
    SUN Microsystems
    http://www.sun.com/developers/support/

  • Create jar with nested jars progammatically

    Hello,
    I want to create a jar which will contain other (nested) jars, and then I want my main class (inside the created jar) to make use of classes within the nested jars. And all this, I want to do programmatically (e.g. using Runtime.exec()). Is this possible?
    Thanks,
    Edited by: 925181 on Apr 3, 2012 4:41 AM
    Edited by: 925181 on Apr 3, 2012 4:46 AM

    And all this, I want to do programmatically (e.g. using Runtime.exec()).I don't understand this part of the question. What will you be doing with Runtime.exec()?

  • Problem to create jar with images

    Hello
    I have a project, it's a frame with a panel that contains a image, I want to create a Jar, but I have to problems, if create a Jar and execute out the project folder, I can't see the images, if I use getClass().getResource, I have other problems, I can't add panels.
    How it's difficult to say, I going to put a link from the project make with eclipse [My project|http://www.megaupload.com/?d=HBPHUWE9] , if someone wants have a look I would be grateful.
    http://www.megaupload.com/?d=HBPHUWE9
    Just look at the package com.constructor.interfaz
    To make the jar use the class InterfazFactoriaPaneles
    Thanks in advance !
    Edited by: Dav1d on Jul 10, 2009 6:11 AM
    Edited by: Dav1d on Jul 10, 2009 6:12 AM

    I explain better:
    I have a Class -> InterfazFactoriaPaneles, with this main
    public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        InterfazFactoriaPaneles application = new InterfazFactoriaPaneles();
                        application.getJFrame().setVisible(true);
    in the Frame I add a JPanel with an image, to load the image I override this method, where com.constructor.imagenes, it's the path where I've got my images :
    public void paintComponent(Graphics g){
              Dimension tamanio = getSize();                    
              ImageIcon     imagenFondo = new ImageIcon("./src/com/constructor/imagenes/patronConstructor.jpg");     
              g.drawImage(imagenFondo.getImage(),0,0,tamanio.width,tamanio.height,null);
              setOpaque(false);
              super.paintComponent(g);
    the with a menu, I remove the panel with the image I load other panel with components (JTextField, JTable, JLabel,...).
    If run the program from eclipse, everything it's ok, if I export into jar file, it works if the jar it's inside the project folder, but if I put the jar in other location, doens't load images, I google from answer and I read to put images path like that: new ImageIcon(getClass().getResource("/com/constructor/imagenes/patronConstructor.jpg")); , but if I do that, and run in eclipse, everything it's ok, but If I export into a Jar, I load the image, but when I try to change to other panel it doesn't work.
    So I do not what's the answer, if someone check my code, and try to make a jar, and the move the jar file into other location, will be able to see images doesn't appears.

  • Creating JAR with NetBeans

    I have several classes and folders with various media in it ( bmp, jpg, wav, ... ) that's included in my project. I want to create a jar file which contains this media. It's not a problem when i'm using console and typing "jar" commands. But can i do this from NetBeans, maybe include this media somehow ...
    i have tryed this, and searched NetBeans help flies but there is no result. I'm just wondering if it's possible ?

    I've a similar question.
    I've created, by sql2java, this package
    build\classes //contains .class file
    build\javadoc //contains .html file
    src\java //contains .java file
    Now i want create a .jar file with all files inside.
    How i can do this?
    In Netbeans i've created a Library by Library manager. I've setted the corrispondent folder, and now the ide allow navigate .class file such as in a jar file. If i double click on one, the ide open corrispondent .java file, and if i want view javadoc, i right-click on .class file and choose "Show javadoc".
    Well, how i can generate a jar file?
    Thanks.

  • CV01N - create document with template - path length

    Hi all,
    i want to create a document from a template document with an original file.
    A popup is displayed and i specify the new path for the new original file.
    --> Error when copying from ... <directory>
    Only 50 characters of the directory string are displayed in the message box???
    Any ideas?
    regards

    hi,
    go to trasaction dc30
    If you are using word file, then select it and click on define template for original file. Make new entry, define all things
    like  Document Type
    Applic.
    Language
    No
    Description
    Copy from...............
    this way you can maintan the template for original file.
    create new document, cleck on create original.
    once you click it, there is a button create with template.
    in dc20 ,click Define data carrier type "server, front end".
    if you are not using content server , then say default entry.
    regards
    nitin
    Award point if useful.

  • CRM Creating Quotation with particular status

    Dear folks,
    I have one requirement in CRM system:
    Generally, We are creating Quotation from the follow-up of Lead transaction. In lead transaction, we have 5 statuses, now the user wants that system should only allow to create Quotation only with the particular Lead status (accepted by sales).. for rest of the 4 status, the system should restrict the user to create the quotation.
    I checked with status profile (for remaining 4 statuses), but it is not only stopping Quotation, it is also stopping all the transactions like activity and task. which is required.
    I checked with Action Profile, (Copy-Document)....it is just creating automatically quotation, once the lead status is accepted. (still user can create followup quotation from other lead statuses).
    Please let me know, how i can achieve this functionality.

    Hi Ravi,
    Thanks for your reply,
    1. Action profile - my condition is status profile....but it is not working, it is not stopping to create the followup transaction in open, in process statuses.
    2. Is it possible to stop creating the quotation only in in-process or Rejected by sales statuses by using status profile... I checked there was an option of create quotation, i set it to forbidden and warning, still it is allowing to create the quotation in the user status (in -process, and rejected by sales).
    I am also working on it.

  • Error while creating a Characteristic Variable with Replacement Path

    Hi all,
        I am trying to create the Characteristic Variable ZVLOWDT (Low Date') with Replacement Path on characteristic ZSTARTDT (Start Date) and it gives the error 'Source to replace 'Low Date' is not defined.
       I have created a User Entry Variable VAR_DATE (Start Date) with interval like '01/01/2009 - 01/15/2009'  and  Customer Exit variable ZVCPDAY (does some calculation based on the input of VAR_DATE) on the same ZSTARTDT characteristic. I want to get the 01/01/2009 (lower range date of the selection) into this Characteristic Variable ZVLOWDT. We are in BI 7.0 and the following are it's properties:
    General Tab:
    Description: Low Date
    Technical Name: ZVLOWDT
    Type of Variable: Characteristic Value
    Processing by: Replacement Path
    Reference Characteristic: ZSTARTDT Start Date
    Details Tab:
    Variable Represents : Single value
    Variable is: Mandatory
    Variable is Ready for Input : unchecked
    Replacement Path Tab: Replacement Rule
    Replace Variable with : Variable
    Variable : VAR_DATE
    Replace with : KEY
    Why I am getting this error, PLEASE ?
    Thanks,
    Venkat.

    Hi Khaja,
       We could derive a Variable value from another Variable with out Customer Exit. There is a white paper.
    First have the User Entry Variable (ZV_X) and it accepts the date range like '01/01/2009 - 01/31/2009'. Next create the Characteristic variable (ZV_Y) of Replacement Path for which source variable will be ZV_X and we could get the 'FROM Date' (01/01/2009) from the selection (ZV_X) into it (ZV_Y).
    While creating the Characteristic variable (ZV_Y) of Replacement Path, I didn't find my newly created ZV_X variable in the list of available variables under 'Variable' header in 'Replacement Path' tab and it is causing the error  'Source to replace variable ZV_Y is not defined'. How could I create the Characteristic variable of Replacement Path, PLEASE ?
    Thanks,
    Venkat.

  • I am trying to find out how to assign files with particular extensions to the appropriate software. At the moment when I create a file using Word it is apparently given the extension .docx but Word doesn't recognise its own files. How do I alocate th

    I am trying to find out how to assign files with particular extensions to the appropriate software. At the moment when I create a file using Word it is apparently given the extension .docx but Word doesn't recognise its own files. How do I allocate the extension .docx to Word? There used to be a way of doing it, I think under "Preferences" but I can't seem to find it.

    Still in the same location:
    File > Get Info > Open with (select) > Change All (button)

  • Create Stanadlone JARs with Third-party API

    Hi,
    I'm working on some personal explorations using OSB 11g, and for that I need to call some JARs with my code. But, the problem is that I'm using Apache POI API for reading MS Excel files. So, how do I go about exporting the POI API along with my code into a single JAR. It has to be one JAR, since to the best of my knowledge OSB doesn't support referencing of multiple JARs at one go.

    See http://java.sun.com/developer/technicalArticles/java_warehouse/single_jar/

  • Regarding text variable with replacement path.

    Hi Friends,
    Please can any one tell me good scenario where we can use text variable with replacement path..
    i have already searched in forum,but that scenario's i did not under stand.
    Please send.
    i will assign points.
    Thanks in advance.
    Thanks & Regards,

    Hi,
    There is a scenario:
    One has to show, a Period like May 2008 for a report. i.e the report which u r showing is common for May 2008. So u create a text variable on this Fiscal Year Period. When u do this, the Text appears on the Top of the report. So later, whenever u execute a report for a particular month, u get that Header as Jue, July etc etc.
    Its just a header. Text Variable promts u to display the Header with our own uploaded Desire Data.
    Steps.
    1) Edit your query
    2) Right click 'keyfigures' or other structure, choose 'new selection',
    3) beside description there is 'variable' button, click and then choose 'new', a variable screen will come out, type in your variable name, description, choose 'replacement path' for processing by. click 'next'.
    http://help.sap.com/saphelp_nw04/helpdata/en/ac/789b3c4d4d8d15e10000000a114084/content.htm
    Assign Points if helped
    Thanks
    Edited by: Noor Ahmed khan on Jul 21, 2008 5:43 PM

  • How to run JavaFX jar with JRE7 on MAC OS Lion 10.7.5 ?

    I have created a bundled JavaFX application jar with ANT on Windows 8 O.S. , 64 bit machine. I have JavaFx2.0 and Java 1.7.0_09 installed on my Window O.S.
    <target name="CreatingJars" depends="Compiling" description="generate the distribution" >
                        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"     
                                 uri="javafx:com.sun.javafx.tools.ant" classpath="${env.JAVA_HOME}/lib/ant-javafx.jar"/>
                              <mkdir dir="${WorkingFolder}/temp/libs"/>
                             <copy todir="${WorkingFolder}/temp/libs">
                             <fileset file="${WorkingFolder}/CustomJars/ProjectLib.jar">
                             </fileset>
                             </copy>
                             <copy todir="${WorkingFolder}/temp/libs">
                             <fileset dir="${WorkingFolder}/libs">
                             </fileset>
                        </copy>
                        <fx:jar destfile="${WorkingFolder}/${app.name}.jar">
                        <fx:application mainClass="${main.class}"/>
                        <fx:resources>
                             <fx:fileset dir="${WorkingFolder}/temp/"/>
                        </fx:resources>
                        <fileset dir="${WorkingFolder}/build"/>
                        <fileset dir="${WorkingFolder}/resources"/>
                        </fx:jar>
         </target> When I am trying to run that JavaFX application jar on MAC OS Lion 10.7.5 using
    java -jar application.jar
    It always shows a dialog "The application require a newer version of Java Run-time" with download link. Even I have downloaded and successfully installed it on my MAC machine but it still shows me the same window.
    java -version is always point to 1.6.
    Then I searched for Java Preferences to point the current JRE 1.7 but I could find Java Preferences at Applications -> Utilities -> Java -> Java Preferences.
    I would like to know -- how to run JavaFX jar with JRE7 on MAC OS Lion 10.7.5? Is their any other way to run the JavaFX application JAR with JRE7?

    Do I need to download the whole JAVA 1.7 on MAC to run the JAR? No
    Can not I run the Jar file with Jre7?Yes, you can.
    This may be because I have downloaded the JRE 1.7Yep, that's correct, the java_home command only works for jdk's - sorry for the confusion.
    For jre7+ versions, only a single Oracle jre version is allowed to be installed on the machine at a time - making a tool like java_home redundant for jre checking.
    Weirdly, jre7u10 does not supplant the Apple Java on the command line path by default. If you just type java -v, then the Apple java version will displayed if you have an old Java 6 from Apple and a new Oracle jre7+.
    The Oracle jre is always located under (also somewhat strangely):
    /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/javaTo test jar launching, I used the willow JavaFX browser pre-release jar available here:
    http://code.google.com/p/willow-browser/downloads/detail?name=Willow-0.1-prerelease.jar
    Then I launched the jar from the command line using:
    /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -jar Willow-0.1-prerelease.jar The JavaFX jar ran fine on jre7 with the above machine.
    The test machine was running Mac OS X 8 with Oracle jre7u10 installed as well as the Apple Java 6 runtime, but no Oracle jdk7+ installed.

  • Creating JAR files programmatically

    I am trying to create JAR files programmatically using the java.util.zip and java.util.jar APIs. I am starting with just a set of directories containing .class files. I can seem to make the JAR but if I try to use any of the classes in it they don't work. But, if I unzip the JAR using WinZip, the classes are usable. So I am somehow building the JAR file incorrectly. Does anyone have any ideas or suggestions? The code is pretty long so I won't post it yet but I can send it to you if you'd like to see it. Contact by email if you'd like to see the code. Thanks.

    What paths are you encoding? Here are a couple of rules:
    1 - All paths are '/' separated, and do not begin with a '/'.
    2 - All paths are relative (see 1) and contain the exact package name of the class, plus the class.
    E.G., the class java.lang.Object would look like this in your jar:
    java/lang/Object.classNothing more or less.

  • Create Roles with acess control in SAP MDM

    Hi Experts,
    I am new to SAP MDM.I want to know how to create roles with access control for various users in SAP MDM.
    Thanks,
    Manoj

    hi,
    in the console; you can create roles with access control and you can assign these roles to users.
    follow this path:
    Console --> repository --> Admin node --> roles,
    here you can create new role. for role here you can maintain
    1. role detail
    2. Functions --here you can restrict the particular role ,  none / Execute the functions.
    3. Tables/fields  -- here you can give access to the role Read only / Read and write, and you can apply constraints also.
    and follow the links:
    http://help.sap.com/saphelp_mdm550/helpdata/en/8e/9f9c427055c66ae10000000a155106/frameset.htm
    http://help.sap.com/saphelp_mdm550/helpdata/en/8e/9f9c427055c66ae10000000a155106/frameset.htm
    http://help.sap.com/saphelp_mdm550/helpdata/en/8e/9f9c427055c66ae10000000a155106/frameset.htm
    http://help.sap.com/saphelp_mdm550/helpdata/en/8e/9f9c427055c66ae10000000a155106/frameset.htm
    http://help.sap.com/saphelp_mdm550/helpdata/en/8e/9f9c427055c66ae10000000a155106/frameset.htm
    hope this may help you,
    Regards,
    Srinivas

Maybe you are looking for

  • FTP file on Appserver to an external system from ABAP

    Hi, I am trying to FTP a file that my program writes to the APPSERVER directory. I used FTP_CONNECT, FTP_COMMAND and FTP_DISCONNECT. I am able to connect to the external system and change to the directory where I have to write the file using cd. The

  • One FileVault won't open, programs on other account won't start

    My fiancee has had problems on her 2006-era MacBook Pro 15". She has FileVault on her primary account, and one other administrator account she doesn't use. Recently, the computer froze while running, and upon reboot it couldn't load up the primary ac

  • Update purchase order was terminated

    Hi expert, When i do release PO, there is a message occur "Update was terminated" and it affects the PO status is still not released. I have tried many times and it is still at the same condition. Then, i go to SM13 and see the detail error message,

  • Bridge Keywords for .gifs

    Wow, What is going on? I spend $2700 on a software suite and I can not put keywords to a .gif or vector files in Bridge???? I tried the preferences "support XMP" does not help. Anyone know any work arounds or patches? Thanks for your help

  • Null Pointer errors with Mapviewer Demo

    Here is the error: xml_response=<?xml version="1.0" encoding="UTF-8"?><oms_error>Message:null Thu Jan 16 15:14:43 MST 2003 Machine Node Name: hoas9ias Severity: 0 Description: java.lang.NullPointerException      at oracle.spatial.mapserver.core.RealW