-
1. Re: Problem in Creating a jar file using java.util.jar and d
jaikiran May 16, 2006 9:21 AM (in response to pikumishra)I have never tried creating a jar programatically, but if you post the exception that you are seeing then may be i (or someone else here) will be able to help you.
-
2. Re: Problem in Creating a jar file using java.util.jar and d
pikumishra May 16, 2006 9:31 AM (in response to pikumishra)Dear Sir,
I am really very happy to get a response from uour side. For your acknowledgement, I am not getting any eroor or exception in this regard. The jar file is created successfully but jboss is unable to deploy it.
Piku -
3. Re: Problem in Creating a jar file using java.util.jar and d
jaikiran May 16, 2006 9:38 AM (in response to pikumishra)What is this jar file? Is it part of some .war or .ear file? Where is this jar file placed? Also, execute the following command on the command prompt, on both the jars(the one which you created manually and the one created programatically) to see the contents of the same. You can even post the contents.
Command:jar -tf yourJarName.jar
-
4. Re: Problem in Creating a jar file using java.util.jar and d
pikumishra May 17, 2006 4:51 AM (in response to pikumishra)Dear JaiKiran,
I am sending my code that will create a jar file from the directory "bin". Please copy my java file and test how it is creating a jar file. Please modify the package name. This program will create a jar file. If you create a jar file using jar -cvf command, the contents wil be same as that of my created jar file. Please help me in this regard. I am unable to proceed. If you find any problem in the code, please modify it and let me know. I am eagerly waiting for your response.
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 ie full path of bin");
jarCreate.close();
}
}