This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
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 = ;.
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
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)
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
Joined: Oct 04, 2013
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.