• 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

compiling with -d option

 
Ranch Hand
Posts: 37
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that -d option is used to tell compiler in which directory to put the .class file. I consider the example from SCJP Sun Certified Programmer for Java 6 Study Guide by Katherine Sierra and Bert Bates (K&B) Page number 793. In this example, there is a command "javac -d ../classes com/wickedlysmart/MyClass.java" and the current director is myProject/source. my question is if we change the current directory to myProject/source/com then can we use three dots after -d option like as
"javac -d .../classes com/wickedlysmart/MyCass.java" to put class file in classes directory or there is any other way to do it.

here is the example:

package com.wickedlysmart; // change to package wickedlysmart
public class MyClass{ }

myProject
|
| ---source|-------com*|--------wickedlysmart|-----MyClass.java
|
|------classes|
 
Greenhorn
Posts: 24
Android Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To go two directories up you'd use: javac -d ../../classes com/wickedlysmart/MyCass.java.
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jack Tol wrote:To go two directories up you'd use: javac -d ../../classes com/wickedlysmart/MyCass.java.



Hello Jack, what you have said is to go ONE directory up and NOT two directories up because the first "." dot refers to the current directory, to go two directories up, you need one more dot.
 
Jack Tol
Greenhorn
Posts: 24
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ikpefua Jacob-Obinyan wrote:

Jack Tol wrote:To go two directories up you'd use: javac -d ../../classes com/wickedlysmart/MyCass.java.



Hello Jack, what you have said is to go ONE directory up and NOT two directories up because the first "." dot refers to the current directory, to go two directories up, you need one more dot.



Hi Ikpefua,

How do you mean?

When the target destination is: myProject/classes
And current path is: myProject/source/com

.. would take you to the path: myProject/source
../.. would take you to the path myProject
and ../../classes would take you to the path myProject/classes, the destination directory.

Please do note that my previous reply was: twodots/twodots/classes.
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jack,
finally I was able to compile the class and put it in the destination directory EXACTLY as specified in Matlloob Hussain's description, with the following invocation:

javac -d ..\..\classes .\.\.\wickedlysmart\MyClass.java

P.S: I used back slash (\) because my system is Microsofts windows 7.

 
Matloob Hussain
Ranch Hand
Posts: 37
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ikpefua Jacob-Obinyan wrote:
javac -d ..\..\classes .\.\.\wickedlysmart\MyClass.java



Hi Ikpefua,

You used .\.\.\wickedlysmart\MyClass.jave to get java file. Could you please explain the use of .\ three times.
 
Jack Tol
Greenhorn
Posts: 24
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matloob Hussain wrote:

Ikpefua Jacob-Obinyan wrote:
javac -d ..\..\classes .\.\.\wickedlysmart\MyClass.java



Hi Ikpefua,

You used .\.\.\wickedlysmart\MyClass.jave to get java file. Could you please explain the use of .\ three times.



I'm not exactly sure why the .\.\.\ is used, but the following works for me in your situation:
javac -d ../../classes/ wickedlysmart/MyClass.java

../../classes gets you to myProject/classes as explained in my previous reply, and you can select class MyClass.java for compilation with wickedlysmart/MyClass.java, seeing as your current working directory is myProject/source/com.

My first reply contained an error in selecting MyClass.java for compilation (com/wickedlysmart/MyClass.java,) my apologies for this. This reply was incorrect because your current working directory is myProject/source/com. From this folder you get to MyClass.java with just wickedlysmart/MyClass.java.
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Matloob,
the reason why I used .\ three times was because I thought... ok since the sintax that Jack specified javac -d ..\..\classes takes us back to start from the myProject directory, why not start the .java file search from the myProject directory, I did that and it worked, that is NOT to say its the most adecuate, it is NOT, and as a matter of fact in java the lesser sintax you use the better.

@Jack your sintax is correct and better than mine. ...Now for the exams I ALMOST certain that you will NOT get a 'wicked' question like this, however on-the-job this makes us 'better equiped' towards managing file systems vs .java and .class files.
 
Matloob Hussain
Ranch Hand
Posts: 37
MySQL Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ikpefua,

Thank you for reply, I was not sure about .\.\.\ now I got it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic