This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes classpath and javac from command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classpath and javac from command line" Watch "classpath and javac from command line" New topic
Author

classpath and javac from command line

Dave Schick
Greenhorn

Joined: Sep 01, 2006
Posts: 13
I'm on a Windows system. C:\ is my root. I created the following directory structure: c:\myProject, c:\myProject\source\com\wickedlysmart, c:\myProject\classes. A pojo file named MyClass.java is in the c:\myProject\source\com\wickedlysmart folder. I'm executing the following from the command prompt (I'm currently at the myProject folder): C:\myProject> javac -classpath c:\myProject\source\com\wickedlysmart MyClass.java

This gives me "cannot read: MyClass.java" error. I thought I was telling javac to look in the absolute path "c:\myProject\source\com\wickedlysmart" for this source file. Where did this greenhorn go wrong? Thanks...


Dave Schick (SCJP 5.0, SCWCD)
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Compiling from the command line can using packages and such can take some geting used to. Since it looks like your MyClass.java file is a stand-alone file (i.e. it doesnt reference any classes not currently on the classpath) you actually don't need to specify any classpath. You do however have to specify the path relative to the current directory. And if you want the .class files generated in the classes folder you use the -d option. Try;

javac -d classes source\com\wickedlysmart\MyClass.java
[ September 01, 2006: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Dude,

Nothing is more frustrating than classpath and compile issues with the JDK. But it's an important learning experience, and we've all been through it.

I think your classpath folder is just too deep. Cut it down to before the package.

I have a few tutorials on using javac and java utilities, inlcuidng one on how to use packages, both in code and with the javac and java utilites. It may be exactly what you need.

http://www.technicalfacilitation.com/examscam/get.php?link=../scja/tutorials

Cheers!

-Cameron
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Dave, welcome aboard!

See if THIS helps. The Sun pages linked from the top of that one are good, too.
[ September 01, 2006: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classpath and javac from command line
 
Similar Threads
Clarification on classpaths
Unable to set CLASSPATH in Linux-based OS
development (package and directories)
knb page# 793 doubt.
compiling with -d option