permaculture playing cards*
The moose likes Beginning Java and the fly likes Related to Javac Command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Related to Javac Command" Watch "Related to Javac Command" New topic
Author

Related to Javac Command

Eric Rounding
Greenhorn

Joined: Jan 26, 2012
Posts: 8
Hi all, hope your well.
I'll give a little groundwork first:
I have a file called GreetingsUniverse.java in TEST\com\scjaexam\tutorial

Now, if my current directory is the tutorial directory I can run the .java file by typing javac -d . GreetingsUniverse.java and it compiles fine.

My question is: If my current directory is the TEST directory. What command do I type to run the GreetingsUniverse.java file?
javac -d com\scjaexam\tutorial\GreetingsUniverse.java gives the error javac: "not a directory" - (this I do not understand)
javac -cp com\scjaexam\tutorial\ gives the error javac: "no source files" - (I understand the sentence, but I do not understand why it's saying it)

Is anyone able to answer the question above and elaborate on anything they think I should know. Or any places online that I can seek tutorials on the matter - doesn't matter how in depth or how long, time is not important knowledge is important.

Thank you in advance to any helpers, much appreciated.
SuperMagicLunchBox.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6



So when you do


It's telling you "not a directory" because it expects a directory after the -d, and the .java file is, big surprise, not a directory.

Similarly, when you do


you're not providing any .java files, so surprise, it complains, "no source files".

Welcome to the Ranch!
Eric Rounding
Greenhorn

Joined: Jan 26, 2012
Posts: 8
I have my GreetingsUniverse.java file in com\scjaexam\tutorial

So why is: javac -cp com\scjaexam\tutorial\ GreetingsUniverse.java
not causing the java file to compile?
The response is: javac: File Not found GreetingsUniverse.java

Could someone give me the exact line I would need to type to get GreetingsUniverse.java to compile when 1) My current directory is TEST, and 2) the GreetingsUniverse.java file is in TEST\com\scjaexam\tutorial.

I am currently unable to understand why javac is not seeing the file when i type the above line.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3720
    
  16
Eric Rounding wrote:So why is: javac -cp com\scjaexam\tutorial\ GreetingsUniverse.java
not causing the java file to compile?
The response is: javac: File Not found GreetingsUniverse.java

Because the -cp (or -classpath) option tells the compiler where to find classes. If you want to tell it where to find source files use the -sourcepath option.


Joanne
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Eric Rounding wrote:
I am currently unable to understand why javac is not seeing the file when i type the above line.


You made the exact same mistake here that you made with your two previous command attempts: You guessed or assumed, rather than reading the documentation and researching.
Eric Rounding
Greenhorn

Joined: Jan 26, 2012
Posts: 8
My understanding so far is that:
-cp tells the compiler where to find class files
-sourcepath tells the compiler where to find source files
-d tells the compiler where to write the class file too. -d is effectively a manual way to package. If the .java file includes a package then the -d path is done first and then the package location is created after. the -d option doesn't create directories but utilises directories already there.

Now i think there may be something wrong with what I'm trying but the SCJA book hasn't revealed it to me, nor google pages, nor youtube tutorials.

I type javac -sourcepath com\scjaexam\tutorial GreetingsUniverse.java

and i get Javac: File Not found: GreetingsUniverse.java


Also thank you for your replies too Jeff - it is true that I may be doing the same things wrong but I am honestly trying to figure out what I'm doing wrong.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Eric Rounding wrote:My understanding so far is that:
-cp tells the compiler where to find class files


Yup. Also the runtime, for the java command and others.

-sourcepath tells the compiler where to find source files


Yup.

-d tells the compiler where to write the class file too.


Yup.

-d is effectively a manual way to package.


I wouldn't put it that way. It just says where the output goes. By default, I think the .class files go in the same directory as their .java files. I wouldn't really consider that "packaging."


If the .java file includes a package then the -d path is done first and then the package location is created after.


Yes. The package becomes a directory subtree under the -d directory.

the -d option doesn't create directories but utilises directories already there.


I'm not 100% sure, but I think that while -d doesn't create the top-level directory (that is, the one named by the -d arg), it does create the package directories below that as needed.


I type javac -sourcepath com\scjaexam\tutorial GreetingsUniverse.java

and i get Javac: File Not found: GreetingsUniverse.java


For that to work, I would expect that, under your current directory, you have com\scjaexam\tutorial\GreetingsUniverse.java. I admit, though, I don't know if I've ever used -sourcepath myself. If I did, it was years and years ago, so I don't recall the details.

If you can post details about your current directory, where the .java file is, what package the class is in, if any, etc., that may help.

Also thank you for your replies too Jeff - it is true that I may be doing the same things wrong but I am honestly trying to figure out what I'm doing wrong.


I know, and I'm not trying to beat you up. Just giving you a little reminder to slow down and pay close attention to the documentation before posting.

Good luck!
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3720
    
  16
Eric Rounding wrote:I type javac -sourcepath com\scjaexam\tutorial GreetingsUniverse.java

and i get Javac: File Not found: GreetingsUniverse.java

i must admit I've never used the sourcepath option but based on the javac help
-sourcepath <path> Specify where to find input source files
I would have expected that to work, but you're right it doesn't. But you don't actually need the sourcepath option. Just use
javac com\scjaexam\tutorial\GreetingsUniverse.java
Eric Rounding
Greenhorn

Joined: Jan 26, 2012
Posts: 8
Hi guys,


javac com\scjaexam\tutorial\GreetingsUniverse.java


this code was what I needed. Upon seeing this everything fell into place.

Thank you both very much for the help, greatly appreciated. I've understood how to compile and run in cmd now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Related to Javac Command