Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy command line Java compile

So I have to send a java project to someone outside our company who has no experience with java and they need to compile it. Is there an easy way to do it on the windows command line that does not require writing out lists of the files?

Personally I think javac should be smart enough to handle

javac *

when in the folder just under the root of the package hierarchy. Is there anything in this ballpark?

Edit: The source folder structure is complex and the is no single entry class so some of the ideas mentioned so far won't work. Thanks though! Think 9 levels deep with code on many levels.

like image 400
nash Avatar asked Mar 15 '10 23:03

nash


2 Answers

From the folder that represents the base of your package hierarchy, assuming your entry point class is called Main, in a package called app,

javac -classpath . app/Main.java

should generate the correct class definitions. The compiler will ferret out the dependencies and compile whatever other classes are needed. The class files will appear in the same directory as their source files.

If, as you say, you have 'more than one entry' class, you will have to at least identify all those top level classes from the dependency hierarchy, which can be listed as further params to javac, specifying the packages as they occur. Like so, assuming you also need to start with other.Entry

javac -classpath . app/Main.java other/Entry.java 

Note that you will still have to figure out which of your classes are tops of independent dependency hierarchies, whether you are creating an ant script or doing it this way.

like image 130
JustJeff Avatar answered Sep 23 '22 22:09

JustJeff


javac BaseProgram.java will compile BaseProgram.java from the current directory, and all classes it references that are available in source code, in the same directory tree.

If BaseProgram references Class1 and Class2, and they are available in Class1.java and Class2.java in the same directory, then they too will get compiled. Likewise if they are in a package, and the package directory is available, they will be compiled.

like image 27
Cheeso Avatar answered Sep 24 '22 22:09

Cheeso