following is part of my code for creating JAR File
public class JarFileManager {
/**
*
*/
public JarFileManager() {
super();
// TODO Auto-generated constructor stub
}
public static JarOutputStream getJarOutPutStream(
String fileLocation){
JarOutputStream jarOutPutStream=null;
try{
jarOutPutStream=new JarOutputStream(new FileOutputStream(fileLocation));
}catch(IOException ioException){
ioException.printStackTrace();
}
return jarOutPutStream;
}
public static void createJarFile()throws Exception{
String
directoryLocation="/home/g.pol/projects/practice/binaryTransfer/classes"; String outFileLocation="/home/g.pol/Desktop/Out.jar";
JarOutputStream jarOutPutStream=getJarOutPutStream(outFileLocation);
FileInputStream in = new FileInputStream(directoryLocation);
}
/**
* @param args
*/
public static void main(String[] args)throws Exception {
createJarFile();
}
}
initially i was just thinking that if we provide directory location then
java code will create jar with all the folders beloow that directory
but i got following exception i know this is not correct way to create FileInputStream for directory
bu how should i create jar which contains my packages
Exception in
thread "main" java.io.FileNotFoundException:
/home/g.pol/projects/practice/binaryTransfer/classes (Is a directory) at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at JarFileManager.createJarFile(JarFileManager.java:42)
at JarFileManager.main(JarFileManager.java:49)
my question is that how to create jar file if i know that at
/home/g.pol/projects/practice/binaryTransfer/classes
i have all my .class files in package struture