aspose file tools*
The moose likes Beginning Java and the fly likes Javac options and directory structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Javac options and directory structure" Watch "Javac options and directory structure" New topic
Author

Javac options and directory structure

Jonathan O'Neill
Greenhorn

Joined: Sep 27, 2012
Posts: 6
For the past few weeks I have been learning how to manipulate java and javac commands when using a command prompt (on windows). Being able to use the -d command has made cleaning up the directories when compiling so much easier. However one problem that I have run into is inheritance and placing class files in a separate directories. I'll give a visual explanation:

Say I have the directory structure of:



Bob extends Human.
Human and Bob are both under the package structure



I am currently situated inside the root directory, so to compile the human.java file and place it into the classes directory I would use the command:



This places the Human.class in said directory structure. (I know most of you know this but bare with me).
However when I try to compile the Bob.java file with the same command it fails and I get errors stating it cannot find the Human Object/Class. I know that if I compile both files at the same time it would work perfectly but this seems to be quite a long entry into a cmd prompt, and having to recompile over and over with a massive String of text would just become tedious. My two questions are:

Is there a simpler way of doing this?
Do I have to use/can I use multiple javac options when compiling my file?

I have scoured the internet for the past few days to get my head around this but can't quite find the right answer. I am grateful for any help!
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Jonathan O'Neill wrote:However when I try to compile the Bob.java file with the same command it fails..


What exact command you did used and what was the compile error as well as source code of files, please mention also.


OCA7
Jonathan O'Neill
Greenhorn

Joined: Sep 27, 2012
Posts: 6
source file

Human.java



Bob.java



The command I enter to command prompt is:




Woops forgot the error:
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

classpath is missing that's why you got compile error as well as you don't need to write import statement because both classes are in same package.
Jonathan O'Neill
Greenhorn

Joined: Sep 27, 2012
Posts: 6
So in relevance I can combine both the -d and -cp option when compiling files?

How do I go about doing that?

Aha cheers for the info on the import statement!
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Jonathan O'Neill wrote:So in relevance I can combine both the -d and -cp option when compiling files?

Yes, Bob extends Human class and that is in classes folder not in source folder, so you have to mention that classpath when you do compile Bob.java.

Jonathan O'Neill
Greenhorn

Joined: Sep 27, 2012
Posts: 6
Ok let me clear this up as im just confused now.
I wish to place the Bob.class in the classe\earth\human directory

What I don't understand is this: How do I combine both -d and -cp into one big statement to input into the cmd prompt?

When I use the this command:



I get the following error:



What am I doing wrong here? Is it the javac command?

I appreciate all the help Ankita thank you.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Ok.Try this..

javac -cp classes -d source\earth\human\Bob.java

-hth
Jonathan O'Neill
Greenhorn

Joined: Sep 27, 2012
Posts: 6
Yes that worked thank you very much. Now to work out why that works! I can do that myself now and always come back to here if I have further questions.

Thank you again for your help Ankita.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38818
    
  23
There is something not quite right about public class Bob extends Human. I would have thought it might be public class Man extends Human or Human bob = new Man()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javac options and directory structure