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();
}
}
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3944148#3944148
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3944148
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user