• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javac and compiled class file

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:



And in this case, if I compile from MyProject directory where would the class be generated?

myProject> javac source/MyClass.java

Larsen.
 
Author
Posts: 116
11
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Larsen Raja
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't javac source/MyClass.java be creating class file in myProjects directory?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Larsen Raja
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Larsen Raja
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic