| Author |
javac and compiled class file
|
Larsen Raja
Ranch Hand
Joined: Nov 28, 2011
Posts: 58
|
|
Hi,
Where would the compiled class file be usually geenrated?
As per K & B,
By default, the compiler puts a .class file in the same directory as the .java source file.
Consider the below case:
[img]
myProject
|
|--source
| |
| |-- MyClass.java
|
|-- classes
|
|--[/img]
And in this case, if I compile from MyProject directory where would the class be generated?
myProject> javac source/MyClass.java
Larsen.
|
 |
Alex Theedom
Greenhorn
Joined: Jan 18, 2012
Posts: 26
|
|
If you compile from the myProjects directory and you want the class file to be compiled into the sources directory use should use the following command:
javac source/MyClass.java
However if you want the code to be compiled into a specific directory (for example the classes directory) you must specify it with the -d option tag like so:
javac -d classes source/MyClass.java
As you can see the K&B book is correct:
By default, the compiler puts a .class file in the same directory as the .java source file.
|
Alex Theedom J2EE Developer.
|
 |
Larsen Raja
Ranch Hand
Joined: Nov 28, 2011
Posts: 58
|
|
|
Shouldn't javac source/MyClass.java be creating class file in myProjects directory?
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
Larsen Raja wrote:Shouldn't javac source/MyClass.java be creating class file in myProjects directory?
By default, the compiler puts a .class file in the same directory as the .java source file.
|
Joanne
|
 |
Larsen Raja
Ranch Hand
Joined: Nov 28, 2011
Posts: 58
|
|
|
Can I conclude that always class files will be created in the source folder of .java file when compiled without -d option and from any directory?
|
 |
Dan Drillich
Ranch Hand
Joined: Jul 09, 2001
Posts: 1127
|
|
javac - The Java Compiler says -
Unless you specify the -d option, the compiler places each class file in the same directory as the corresponding source file.
Regards,
Dan
|
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
|
 |
Larsen Raja
Ranch Hand
Joined: Nov 28, 2011
Posts: 58
|
|
|
Thanks.
|
 |
 |
|
|
subject: javac and compiled class file
|
|
|