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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

how to jar the resulting .class files after compilation

Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello all,
Right now the code that I have posted below will compile the two .java files provided....and it will also jar these files...But I want to jar the resulting .class files that get generated after the compilation....

However, the compile method doesn't return any files, it returns a boolean that indicates whether the compile was successful or unsuccessful. After a successful compilation The .class files are placed inside my working directory. As the code works now, it jars the .java files because those are the files that i past it. Can anyone help me to figure out how to jar the .class files that result from the compile?

//This method allows the user to name the jar file and choose the files to jar

private File interfaceFile;
private File handlerFile;

public void compileAndJar()
System.out.println("Entering the compileANdJar() Method....");

// These are the files to include in the Jar file
String[] filenames = new String[]{interfaceFile.getName(), handlerFile.getName()};
System.out.println("INTERFACE FILE NAME----> "+interfaceFile.getName()+" HANDLER FILE NAME----> "+handlerFile.getName());

//compile the interface and handler files
{ comp = new, null);
boolean iFacesuccess = comp.compile(filenames);
catch(Exception e)

// Create a buffer for reading the files
byte[] buf = new byte[1024];

// Create the jar file
String outFilename = jarTextField1.getText(); //Allow the user to set this variable
System.out.println("JAR FILE NAME----> "+outFilename);

JarOutputStream out = new JarOutputStream(new FileOutputStream(outFilename));

// Compress the files
for (int i=0; i<filenames.length; i++)
FileInputStream in = new FileInputStream(filenames[i]);

// Add JAR entry to output stream.
out.putNextEntry(new JarEntry(filenames[i]));

// Transfer bytes from the file to the JAR file
int len;
while ((len = > 0) {
out.write(buf, 0, len);

// Complete the entry

// Complete the JAR file
catch (IOException ioe)
[ June 15, 2005: Message edited by: Durand Grimmett ]
author and iconoclast
Posts: 24203
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Continued here.
Destroy anything that stands in your way. Except this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic