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.

Similar Messages

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

  • 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

  • Append to jar file using java codings

    Hi,
    I have codings which could create jar file and write datas in it. but i need to append datas to existing jar file using java codings.Here i have attached my codings which will write datas to new jar file. when ever i use this my existing contents gets overritten. wat can i add to this to append.
    FileOutputStream stream = new FileOutputStream(archiveFile,true);// archive file is jar file name
         JarOutputStream out = new JarOutputStream(stream, new Manifest());
    JarEntry jarAdd = new JarEntry(tobeJar.getName()); // tobejar is a file to write in jar.
    jarAdd.setTime(tobeJar.lastModified());
                   out.putNextEntry(jarAdd);
                   // Write file to archive
                   FileInputStream in = new FileInputStream(tobeJar);
                   while (true) {
                   int nRead = in.read(buffer, 0, buffer.length);
                   if (nRead <= 0)
                   break;
                   out.write(buffer, 0, nRead);
                   out.closeEntry();
    out.close();

    JarInputStream in = new JarInputStream(new FileInputStream(oldJarName), true); // oldJarName is the JAR that contains all the files we want to keep
    JarOutputStream out = new JarOutputStream(new FileOutputStream(tempJarName)); // this is your "out" variable
    // copy the files from the old JAR to the new, but don't close the new JAR yet
    JarEntry inEnt;
    while ((inEnt = in.getNextJarEntry()) != null) {
      JarEntry outEnt = new JarEntry(inEnt); // copy size, modification time etc.
      byte[] data = inEnt.getSize();
      in.read(data); // read data for this old entry
      in.closeEntry();
      out.putNextEntry(outEnt);
      out.write(data); // copy it to the new entry
      out.closeEntry();
    // now write an entry for the file we want to append - this is the OP's code
    JarEntry jarAdd = new JarEntry(tobeJar.getName()); // tobejar is a file to write in jar.
    jarAdd.setTime(tobeJar.lastModified());
    out.putNextEntry(jarAdd);
    // Write file to archive
    FileInputStream in = new FileInputStream(tobeJar);
    while (true) {
    int nRead = in.read(buffer, 0, buffer.length);
    if (nRead <= 0)
    break;
    out.write(buffer, 0, nRead);
    out.closeEntry();
    // and *now* we close the new JAR file.
    out.close();
    // We then delete the old JAR file...
    new File(oldJarName).delete();
    // ... and rename the new JAR file to use the old one's name.
    new File(tempJarName).renameTo(new File(oldJarName));

  • Create crystal report file using JAVA

    Can someone tell me how to a Create crystal report file using JAVA Programming
    I want a very simple example

    Please help me. It's urgent.[http://catb.org/~esr/faqs/smart-questions.html#urgent]
    Be back in an hour or two...

  • I need to create  .pst  ext . file using java,whi will import in ms outlook

    {color:#ff0000}*I need to create .PST extension file using java which will be able to import in ms outlook,and that .pst file will contain root folder (like Personal Folders) and inbox,sent mail*{color}
    give me some hint It is essential task .we have to implement code in  java

    I'm using the thin drivers.
    The answer to your question is no, you do not need to create a DSN to connect to Oracle. The Oracle thin driver is all that is required. Your code looks OK to me, I'm assuming that you xxx'd out the IP, and that you are using a real IP in the actual code.
    The message you got back is pretty generic, but can indicate that the Oracle database listener isn't available. Perhaps the database is on a different port, or perhaps the listerner isn't running. Perhaps you have the IP address wrong.
    So, to be very basic:
    1) Can you ping the server you are trying to connect to? This makes sure you are using a valid IP address.
    2) Can you connect to the Oracle server from an Oracle client? This makes sure the listener is running properly, and that you know the correct port number and login information (The port number could be in a local or server based TNS file, or available through an Oracle names server. You might try using the program tnsping if it is available on the client for validation.
    3) If you can do 1 and 2, then be sure you are using the same connection parameters (server, port userid and password) that worked with 2.
    4) Verify that you are using (pointing to) the correct set of Oracle classes for the thin connection. This can be tricky if you have different versions of Oracle on the client then on the server, but is documented on the Oracle website.
    5) If everything checks out, you might want to verify that you are using the most recent versions of the thin drivers, including the Oracle patches.
    Hope it helps - good luck,
    Joel

  • 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

  • Unzipping files using java.util

    I am trying to unzip files using java.util.zip
    It works fine when I am trying to unzip a file that is already residing on the server.
    But I want to unzip the file that user will upload to the server .
    My code is uploading zip file to server but not able to unzip this zip file giving error
    java.util.zip.ZipException: error in opening zip file
    What could be the problem
    I am not getting exactly
    Can you give me any clue
    Thanks

    sounds like the uploading is the problem. Are you FTPing the file? If so check that it's being transferred in binary, not ascii.

  • How to record .jar file using Java Protocol

    Hi,
    I Tried to record .jar using Java protocol by using HR Loadrunner 11.0 Version tool.
    Am unable to record the application.
    Can any one suggest me the process of recording .jar file using load runner?
    Thanks,
    Venkat

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

  • How can I use java.util.Date and change display format.

    Hello All,
    I want to use java.util.Date in View Context and in Custom Control Context of Web dynpro java. When i mapped of a Input Field to the java.util.Date then message shows that its not supported. Plz suggest me how to handle Date with different formats ??

    If you always want the user to enter the date in dd/MM/yyyy, you can do the following.
    Goto Local Dictonary -> Simple types in your project and create a type known as "InputDate" (or whatever you feel) of built-in type 'Date'.
    Now specifiy its format in the 'Representation' tab as "dd/MM/yyyy" (case-senstive).
    Now declare a value attribute say "inputdate" in your context with this type and bind the inputfield to this context value attribute.
    This will solve your problem.
    But if you want the user to input date depending on the region he belongs, change the default locale date in Control Panel->Regional and Language Options->Change to English(UK) -> Customize -> Date Tab -> Sort Date Format to dd/MM/yyyy.
    Now clear the cache, delete temporary files and restart the machine. This should solve the problem.

  • Making Executable Jar file using java Application

    Following Program creates the jar file at specified location. but, I wonder why this file does not execute on double clicking on it, in spite of that the Manifest file contain correct main class file name
    //MakJar.java
    import java.io.*;
    public class MakJar
    public static void main(String[] args)throws IOException{
    Process p;
    String str="D:\\Himesh\\JFiles";
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter(str+"\\mainClass.txt"));
    out.write("Main-Class: TestFrame\n");
    out.close();
    } catch (IOException e) {
    try
         p=Runtime.getRuntime().exec("cmd /c D:\\Java6\\jdk1.6.0\\bin\\javac.exe "+str+"\\TestFrame.java");
         p=Runtime.getRuntime().exec("cmd /c D:\\Java6\\jdk1.6.0\\bin\\jar cvmf "+str+"\\mainClass.txt "+str+"\\Demo.jar "+str+"\\*.class");
    catch(IOException e)
    System.err.println("Error on exec() method");
    e.printStackTrace();
    }

    Sir,
    On execute the jar using a "java -jar. . ." command. it gives the error--
    "Exception in thread "main" java.lang.NoClassDefFoundError : TestFrame"
    On Extracting the files from jar file made by the java program,i found that the manifist file ( containing the name of main class) and t the class file are included in the jar file.
    But if I make the jar file manually it works perfectly.I have even reinstalled the java but the problem persists
    Same thing happen if i use MS-DOS batch file.
    ??????If i put the batch file in the same directory and execute it The resulting jar file works,But
    ??????if the batch file is executed from outside the directory The resulting jar file fails execute.
    what should i do???

  • Creating an XML file using Java Standalone

    Hi,
    My problem is -
    1) write a java stand alone retrieving data from database and put the data in XML format (i.e; we have to create an XML file).
    How to do this? Could any one of you please suggest me how to code or can i have any links that refer the code snippets.
    Thanks.

    Could someone give me a link with information on how SAX is used to create an XML?
    null

  • Problem of creating FoxPro dbf file in Java

    Hi all,
    I tried to create a empty FoxPro dbf file with the following codes in Java:
    sqlString = "create table mytable.dbf ( Name C(10) )"
    queryStatement.execute( sqlString );
    And it did create a "mytable.dbf" file. However, when I opened it with Excel, it said that it is not a recognizable format. If I continued to open it, I could only see some junks inside.
    I am using Windows 2000 Pro and j2sdk 1.4.2. I also have Microsoft Visual FoxPro Driver installed. This works perfectly with SQL commands like SELECT and INSERT, but just doesn't work for CREATE. Does any body have a clue of what I should do? Thanks a lot!
    Alex

    You may want to get rid of the .dbf part in your create statement. Foxpro doesn't need that. It should be:
    create table mytable(myfield c(10)), not create table mytable.dbf(myfield c(10)).
    This may help. If people are using a recent version of Excel it should be able to open up foxpro tables...I do it all the time. What version of Foxpro are you running, and what version of the dbc driver for Foxpro are you using?
    Eric

  • How to run a jar file using Java application.

    Hi all,
    I know that jar file can run using the following command, using the command prompt.
    java -jar jar-fileBut I don't know how to run that command through a Java code. Hope it's clear to you.
    So can you please explain how can I do it.
    Thanks,
    itsjava

    rayon.m wrote:
    The solution given by ropp appears to have nothing to do with what you asked about.Ok sir, I got the point.
    I've try a test as follows. But it doesn't give any output. Even not an exception.
            try {
                String[] temp = new String[]{"java", " -jar", " MainApp.jar"};
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(temp);
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);
                System.out.println("Temp_Values");
            catch(InterruptedException ex) {
                System.out.println(ex.getMessage());
            catch (IOException ex) {
                System.out.println(ex.getMessage());
            }I've debug and see, but the exitValue is even not exist at run time. Can you tell me where I'm going wrong.

Maybe you are looking for

  • How do i replace my hard drive? dv4

    I have a Pavilion DV4 Entertainment Laptop.  I replaced the hard drive and now it is acting like the drive isn't installed.  When I check BIOS, it says no HDD exists.  Is there something I am missing?  I made sure the drive is seated, it has 3 screws

  • Printer stopped working with Firefox but works fine with Safari. We have a MacBook Pro OS 10.5.8.

    Our R380 Printer has been working perfectly with Firefox in printing web pages and email. However, now it will not even attempt to print web pages or email. It's like it doesn't even know that a printer is connected. But when I launch Safari, the pri

  • MDNSResponder has to be reloaded after reboot

    Hey All - I'm running Snow Leopard (10.6.8) and the first time I restarted after the last update, my DNS was broken. Both ethernet and Airport showed that they were connected and had IP addresses, but DNS can't resolve anything. I could access nothin

  • Warning unresponsive script came up but won't let me stop the script or continue it or anything. help!

    I'm on a MacBook air. I tried to close Firefox and it won't let me, I tried uninstalling it and won't let me, and I tried shutting down my computer and still won't let me do anything! Someone please help me! I already called Apple and they said they

  • Problem in RBDMIDOC report

    Hi, I am using Idoc to transfer HR Master data from SAP to CRM and am using message type HRMD_ABA. Iam using RBDMIDOC (TRAN - BD21) to create DIOC and the transfer the data which is schedule periodically. Now my reqirement is that i want to use INSER