This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to jar the resulting .class files after compilation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

how to jar the resulting .class files after compilation

Durand Grimmett

Joined: Jun 02, 2004
Posts: 16
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

Joined: Jul 08, 2003
Posts: 24193

Continued here.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: how to jar the resulting .class files after compilation
It's not a secret anymore!