aspose file tools*
The moose likes Beginning Java and the fly likes Java file 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 "Java file directory structure" Watch "Java file directory structure" New topic
Author

Java file directory structure

Robert D. Smith
Ranch Hand

Joined: Oct 04, 2013
Posts: 143
    
    5
I've decided to lose my IDE and start coding with a text editor. Apparently understanding java and javac are on the certification exam, and I need to learn it anyway. (I only used the IDE for the syntax highlighting and having the error messages in the debug window). Java and javac run fine. Just a simple Hello World app.



Program compiles, with no errors, and runs just like one would expect. What confuses me, though, is that the app runs fine, as long as I run it from the class directory. If I attempt to run it from any other directory it returns the Error: Could not find or load main class <pathname>.

CLASSPATH = ;.
Windows 8.1
java -version: 1.8.0-ea

Anyway, I'm lost and confused. Couldn't tell you how many sites I looked through. Seems most just assume one is using the IDE, and those that actually give a directory structure only show a partial as it relates to packages.


There are worse crimes than burning books. One of them is not reading them. Ray Bradbury
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10384
    
    8

The root cause is CLASSPATH
Classpath is the path (or a bunch of paths) given to the JVM as probable locations where the required classes might be found. In addition to these, the JVM will also look in the current directory for the required classes (which explains why it runs from the current directory)
For more information, you can refer to http://www.coderanch.com/how-to/java/HowToSetTheClasspath

Robert D. Smith wrote:(I only used the IDE for the syntax highlighting and having the error messages in the debug window)

I would say, getting rid of the IDE at a beginners stage is a very smart thing to do. In case you prefer highlighting (I agree, can be very useful) you might want to consider some advanced editors like JEdit which can do the highlighting/indentation for you, but are not full blown IDEs (in the sense that they do things under the hood, things, which as a developer, you need to know)


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
Maneesh Godbole wrote: . . . In addition to these, the JVM will also look in the current directory for the required classes . . .
I thought it only looks in the current directory by default if no CLASSPATH has been set elsewhere. The CLASSPATH ;. obviously interferes with its finding the necessary files.
Robert D. Smith
Ranch Hand

Joined: Oct 04, 2013
Posts: 143
    
    5
Thanks for the replies. The sad thing is I saw a handful of videos on setting up the paths on youtube and all of them set theirs up that way. And thanks for the link; I don't know how I missed that because the FAQs were the first place I turned.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2419
    
    7

To keep things simple, you shouldn't need to set classpath when compiling or running your programs. Unless you use external libraries.

One thing to remember is wherever you execute your command is where the compiler/jvm will look. So the actual java or class files is "relative" to your current directory.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java file directory structure