Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
    Bookmark Topic Watch Topic
  • New Topic

how to jar the resulting .class files after compilation

Durand Grimmett
Posts: 16
  • Mark post as helpful
  • send pies
  • 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 ]
Ernest Friedman-Hill
author and iconoclast
Posts: 24208
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Continued here.
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic