How to put Chinese character in jar file by java.util.jar.Manifest?

Now I want to develop a simple package tool which can modify some property in manifest.mf of jar files,but the Manifest class's putValue method only can correctly save English character.why?
And how can I put Chinese character?
the code is:
Attributes ab = mf.getMainAttributes();
ab.putValue("agent-Name", agent);

Attribute values can contain any character and it will be UTF-8 encoded when written to the manifest, according to Javadoc.
What makes you think that this mechanism fails? What do you see instead of the Chinese character? And what tool/editor/program you use to see it? I did not try myself, but according to the Javadoc there should be no problem.

Similar Messages

  • Problem in Creating a jar file using java.util.jar and deploying in jboss 4

    Dear Techies,
    I am facing this peculiar problem. I am creating a jar file programmatically using java.util.jar api. The jar file is created but Jboss AS is unable to deploy this jar file. I have also tested that my created jar file contains the same files. When I create a jar file from the command using jar -cvf command, Jboss is able to deploy. I am sending the code , please review it and let me know the problem. I badly require your help. I am unable to proceeed in this regard. Please help me.
    package com.rrs.corona.solutionsacceleratorstudio.solutionadapter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.util.jar.JarEntry;
    import java.util.jar.JarOutputStream;
    import java.util.jar.Manifest;
    import com.rrs.corona.solutionsacceleratorstudio.SASConstants;
    * @author Piku Mishra
    public class JarCreation
         * File object
         File file;
         * JarOutputStream object to create a jar file
         JarOutputStream jarOutput ;
         * File of the generated jar file
         String jarFileName = "rrs.jar";
         *To create a Manifest.mf file
         Manifest manifest = null;
         //Attributes atr = null;
         * Default Constructor to specify the path and
         * name of the jar file
         * @param destnPath of type String denoting the path of the generated jar file
         public JarCreation(String destnPath)
         {//This constructor initializes the destination path and file name of the jar file
              try
                   manifest = new Manifest();
                   jarOutput = new JarOutputStream(new FileOutputStream(destnPath+"/"+jarFileName),manifest);
              catch(Exception e)
                   e.printStackTrace();
         public JarCreation()
         * This method is used to obtain the list of files present in a
         * directory
         * @param path of type String specifying the path of directory containing the files
         * @return the list of files from a particular directory
         public File[] getFiles(String path)
         {//This method is used to obtain the list of files in a directory
              try
                   file = new File(path);
              catch(Exception e)
                   e.printStackTrace();
              return file.listFiles();
         * This method is used to create a jar file from a directory
         * @param path of type String specifying the directory to make jar
         public void createJar(String path)
         {//This method is used to create a jar file from
              // a directory. If the directory contains several nested directory
              //it will work.
              try
                   byte[] buff = new byte[2048];
                   File[] fileList = getFiles(path);
                   for(int i=0;i<fileList.length;i++)
                        if(fileList.isDirectory())
                             createJar(fileList[i].getAbsolutePath());//Recusive method to get the files
                        else
                             FileInputStream fin = new FileInputStream(fileList[i]);
                             String temp = fileList[i].getAbsolutePath();
                             String subTemp = temp.substring(temp.indexOf("bin")+4,temp.length());
    //                         System.out.println( subTemp+":"+fin.getChannel().size());
                             jarOutput.putNextEntry(new JarEntry(subTemp));
                             int len ;
                             while((len=fin.read(buff))>0)
                                  jarOutput.write(buff,0,len);
                             fin.close();
              catch( Exception e )
                   e.printStackTrace();
         * Method used to close the object for JarOutputStream
         public void close()
         {//This method is used to close the
              //JarOutputStream
              try
                   jarOutput.flush();
                   jarOutput.close();
              catch(Exception e)
                   e.printStackTrace();
         public static void main( String[] args )
              JarCreation jarCreate = new JarCreation("destnation path where jar file will be created /");
              jarCreate.createJar("put your source directory");
              jarCreate.close();

    Hi,
    I have gone through your code and the problem is that when you create jar it takes a complete path address (which is called using getAbsolutePath ) (when you extract you see the path; C:\..\...\..\ )
    You need to truncate this complete path and take only the path address where your files are stored and the problem must be solved.

  • Modifying JAR file using java.util.jar package  over the network

    Hello,
    I am modifying a JAR file programmatically using java.util.jar package. The time taken to save the contents to a local disk is very less (around 1 sec) . When I tried modifying the JAR from a remote machine over the network (from mapped drive or shared folder of WIN NT), the time taken to save is 15-20 times more.
    I am recreating the whole JAR while modifying. Is there any way to improve the performance. Or is it possible to write only the changed files?
    Thanks,
    Prasad Y S.

    When you "update" a jar file, you must always recreate it from scratch.

  • How to put chinese character in the Manifest file

    Hi,
    I want to know that how can we put chinese characters in the manifest file. Please suggest a solution.
    Regards

    [slightly confused stuff removed]Sorry, AmitChalwade123456, I know trolling can be very funny, but you're confusing the sh*t out of newbies with this almost-seems-usefull kind of talk.
    Stop that.
    And in case you really meant that seriously: Please refrain from giving advice with regard to encoding. What you posted is wrong (to put it mildly).

  • Output chinese character to CSV file in UNIX

    Hi
    I encountered ABAP dump whenever output chinese character to CSV file in UNIX in ECC6. Error show as
    "At the conversion of a text from codepage '4102' to codepage '1100':
    - a character was found that cannot be displayed in one of the two
    codepages;
    - or it was detected that this conversion is not supported"
    The program with coding of statement OPEN DATASET xxxxx FOR OUTPUT IN TEXT MODE  ENCODING NON-UNICODE. Reason to output to OPEN statement to non-unicode as users would like to open the csv file thru Excel directly. They do not wish to open the text file in Excel. Can Experts please share with me how to overcome the problem?
    Thanks
    Kang Ring

    May be you could give a try with the following code and check
    OPEN DATASET xxxxx FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE CODEPAGE '4103'.
    Vikranth

  • How to escape newline character(nl) in file content conversion parameter?

    Hi Experts,
    How to escape newline character(nl) in file content conversion parameter?
    For example:
    field1field2field3
    field4field5field6
    Means Item is splitted in two lines.
    I want to SKIP new line character
    and to collect all SIX fields.
    What will be the file content conversion parameter?
    Thanks in Advance..........

    Hi,
    as far as i know there is nothing in the standard. But the question is why dont you combine at mapping the fields into only structure?
    Regards,
    Udo

  • How to remove a character in a file??

    I'm not getting how to remove a character from a file.Could anyone post a method to do this?Any help would be appreciable.

    Ohhh... and one more thing... unless you're really unlucky, a few "extranious trailing nulls" won't make a jot of difference to the size of the file on disk, each each file "fills" whole blocks anyway, which is 1K (I think) on both fister and *nix... unless of course we're talking "lots" of trailing-nulls, or lots-and-lots of files.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to run .jar on linux & how to create .jar file using java?

    hi, may i know how to run .jar on linux & how to create .jar file using java? Can u provide the steps on doing it.
    thanks in advance.

    Look at the manual page for jar:
    # man jar
    Also you can run them by doing:
    # java -jar Prog.jar

  • Help:how to use java.util.jar to zip or unzip a binary file.

    how to use java.util.jar to zip or unzip a binary file or a file contain native code.

    It may help you to know how I add JARs
    1. I open my Project (myProject)
    2. I Mount the JAR to the FileSystem (like mypackages.jar = which includes com.mus.de.myClass.java)
    3. I Mount the File to the FileSystem (like c:\..myfiles..\myProject)
    3.1 I add the File to my Project
    4. I select File | New -> Classes | Main
    4.1 I typed "import com.mus.de.myClass.java" to refer to this package.
    4.2 I called some of the public methods
    thats it
    Andreas

  • OpenScript/How to add .jar file to Java Code in relative path

    Hi all,
    I want to add a .jar file which can be executed separately (like "java -jar A.jar") to my recorded Java Code.I've read this wiki http://everest2.us.oracle.com/wiki/Generic_JAR_Project about how to add a .jar file to "Assets", however, I cannot figure out how to use the .jarr file in Java code,I mean , how to get this .jar file like the method the databank added in "Assets"?
    Things I did are as followed:
    1.Execute my .jar file in OpenScript Java code with absolute path like this:
    String cmd = "C:\Users\A.jar";
    Runtime.getRuntime().exec(cmd);
    This does work, but must set a absolute path in Java code like "C:\User\A.jar" ,which is not the workaround I want (I need my scripts can be run on other machines).
    2.Try to get its current path with following codes:
    File directory = new File(".");
    String currentPath=directory.getCanonicalPath();
    However,though this can get its absolute path (which is the the project path) in Eclipse like "C:\Users\Workspace\testProject", this only gets "C:\OracleATS\openScript" in OpenScript.
    I thought to copy my .jar file to the project path , got its current path in java code first,then can know the path of .jar file, but this workaround failed because of the above reason.
    I notice that in the "Assets" there are "Databanks","Object Libraries","JAR Files","Scripts". Since the databanks and scripts that added to "Databanks" and "Scripts" can be got or run in Java Code like:
    *getDatabank("DatabankName").getNextDatabankRecord(); String data = eval("{{db.DatabankName.data}}");*
    *or getScript("ScriptName").run();*
    *Is there a method to get and run the jar file added to "Assets\JAR Files" like the above?*
    Thank you very much!
    Regards,
    Angyoung

    Hi DM,
    Thanks for your reply!
    I've found a workaround,which is calling OpenScript's APIs ,such as this.getScriptPackage().getRepository() and this.getScriptPackage().getWorkspace(),etc to locate the .jar file.
    And this workaround can still work even though the script is run on other machine.
    Sorry to reply you so late!
    Regards,
    Angyoung

  • Protect jar file from unzip utility

    Hi
    I have an application in .jar file and I don't want that the client
    can extract or unzip and see the contents of my .jar file.But still the .jar file
    could run by mouse double click or java -jar command.
    Anyone can give me an idea how to do it.
    Thanks...

    If java can read it on your client's machine, the client can read it. There is no way to prevent this. Here's the general cycle:
    int protectionMode = chooseProtectionMode();
    boolean haveCustomers = true;
    while (haveCustomers)
      switch (protectionMode)
        case OBFUSCATE: 
          //You can obfuscate your code to make it (marginally) harder to
          //reverse-engineer.  If your client is really interested in your
          //code, this won't keep them from figuring out what it does.
          break;
        case ENCRYPT:
          // You can encrypt most of your class files, and build a
          // decrypting classloader, and build a framework that calls
          // the decrypting classloader to get at the rest of the jar. 
          // Of course, your client can just arrange to call your
          // classloader from their own, and write the (decrypted)
          // classfiles to disk, and then reverse engineer them.
          protectionMode = OBFUSCATE;
          break;
        case STATECHECK:
          // You can put some kind of check in your decrypting classloader
          // that calls System.exit() if it discovers it's being called in
          // such an unfriendly way.  Your client will take about 10 minutes
          // to find and remove the check.
          protectionMode = ENCRYPT;
          break;
        case REMOTE:
          // You can keep your code on your server and let the client run
          // something that talks to it.  The client will complain
          // vociferously, and refuse to use your app. 
          haveCustomers = false;
          break;
        default:
          // You can decide to stop stressing over something you can't
          // help, and write code that people will buy
      }(Sorry - in an odd mood, seen this question or one like it too often recently, not enough sleep...)

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

  • Maintain local in-house jar files while java plug-in is upgraded

    I have some in-house developed jar files which are kept at C:\Program Files\Java\jre_xxx\lib\applet. However, starting from Jre 1.4.2, there is
    an "autoupdate" feature which allows auto-download and installation of newer version of JRE to the client PC.
    Though it is a good feature, there is problem in using the in-house developed jar files because the local jar files will not copied to the
    corresponding java jre directory automatically. I need to copied the jar files manually to the new jre\lib\applet directory.
    Besides me, there is many users at the site encounter the same problem. Are there any suggestions to improve the matter.
    Thank you.
    Newton

    This is why you should not put your files inside Java's system directories.
    Bite the bullet and make the change - move your files outside of Java's directories.
    The alternative is to develop and maintain a corporate intranet Java update functionality.

  • Creating jar file including 2 another jar files

    hi
    My project has java files, properties files,batch files as well as two jar files,mail.jar & activation.jar(for importing packages).
    I have to include these jar files while setting environment variables.
    Now i want to make "MyPrj.jar" file for myproject ,can anyone pls help me how to include these all files into a single jar file. and how to make setup file
    I have tried to extract out .class files of mail.jar & activation.jar & i ve created MyPrj.jar by including all class files(including class files of mail.jar & activation.jar) but manifest file(headers) are not added to MyPrj.jar.
    i have also tried to give mail.jar & activation.jar in Class-Path of menifest file, but it is also not working.
    Pls Help
    Thanks a lot

    [http://sourceforge.net/projects/one-jar]
    "One-JAR(TM) is a simple solution to a vexing problem in Java: how to distribute an application as a single jar-file, when it depends on multiple other jar-files. One-JAR uses a custom classloader to discover library jar files inside the main jar. "

  • Importing jar files for Java mapping ?

    Hi Guys,
    I am developing a java mapping by using Eclipse. I want to know <b>where can i find the jar files of xi which i need to import into Eclipse to develop the Java Mapping</b>.
    I need to use the external jar files for this Java Mapping and once i am done with the mapping, <b>How can import the external .jar files into XI</b>
    any hep would be really appreciated
    Thanks,
    srini

    Sri,
    check <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions's XI FAQ</a> for the location of .jar of mapping API.
    <b>5. Where can I find aii_map_api.jar to create my Java mapping?</b>
    After you have created your java mapping class, export your project to a .jar file and import this .jar into Imported Archives (under Mapping node) in Integration Repository.
    Regards,
    Henrique.

Maybe you are looking for