• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to create jar file with the help of java code

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic