flexinIT
flexinIT

Reputation: 431

Is there a way to get .class file from .java file

I have a method that is returning a group of .java files, but I need the .class files of these java files... Is there a simple way to do this?

Here is a sector of the code I'm using to return a list of .java files

files = retrieveFiles.listFilesForFolder(folder);
for(File currentFile: files){
     //for each file i need to get the .class file
}

Upvotes: 0

Views: 380

Answers (2)

Aric Hunter
Aric Hunter

Reputation: 93

Not sure if you're using OS X or windows, but in either case, you should be aple to use the javac command which compiles .java files and creates .class files.

Then, it's just a matter of figuring out how to run the javac command in your java script, which depends on your os (whether it's unix based or not): http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/

More on the javac command: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html

Upvotes: 0

Andreas Dolk
Andreas Dolk

Reputation: 114767

Java SDK 6 introduced the Compiler API. That allows to compile java code from within java applications.

Further reading:

Upvotes: 2

Related Questions