compile whole project help

F

f

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?

Thanks,

ff
 
A

Anthony Borla

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
 
M

Mladen Adamovic

I think you should use some make tool.
You might want to use GNU make,
but I strongly recommend you ant, platform independent
Java make tool, look at the:
http://ant.apache.org
 
F

f

does that compile -subpackage1 also?

Anthony Borla said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top