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.getAbsolutePath());//Recusive method to get the files
}
else
{
FileInputStream fin = new FileInputStream(fileList);
String temp = fileList.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();
}
}

