f said:
I have the following java code at file system:
-MyProject
-class
-src
-com
-company
-project
file1.java
file2.java
-subpackage1
file11.java
-subpackage2
file21.java
file22.java
I am compiling with command line javac. Is there a
command to compile all the java file together and put
the result at my class directory?
Assuming that 'MyProject' is in the top-level directory, and the requisite
'package' and 'import' statements are correctly in place, then the following
should do as you require:
javac -d MyProject/class
MyProject/src/com/company/project/*.java
Note: the above should be a single line
Assuming 'file1.class' as the application launch file, then you can execute
this as:
cd MyProject/class
java MyProject.src.com.company.project.file1
I'm not sure, however, that you really want such a - IMO - convoluted
package structure. One reason I say this is because you will find your
'class' directory containing the entire project directoy hierarchy ! This
occurs, naturally enough, in order to match the package structure. May I
suggest two things. Firstly, change to the following directory structure
[alter your package statements accordingly]:
-com
-company
-MyProject
file1.java
file2.java
-subpackage1
file11.java
-subpackage2
file21.java
file22.java
Secondly, have the '.class' files created on another drive [if you are on a
Windows system -another mounted directory for *NIX people] mimicing the same
structure. For example, on a Windows system, assuming your source is on
drive X:, then target your '.class' files for drive Y: - this is shown:
X:
cd \
javac -d Y:\ com/company/MyProject/*.java
The '.class' files now exist in the same directoy structure on drive Y:, so
to execute:
Y:
cd \
java com.company.MyProject.file1
Of course drive Y: could merely be a SUBSTed drive [i.e. an alias for a
directory located locally, or remotely located - even located on drive X:
!]. I believe it is a very clean, simple way of separating source and
'.class' files which can be accomplished from the command-line without batch
files / scripts.
I hope this helps.
Anthony Borla