This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Originally posted by Sam Smoot: I have the following code that executes through eclipse, well, ok I guess. I do have some issues, however.
First issue is that when I try to execute the file from the console I get the following message:
To me this sounds like a classpath problem. Is the AddID.class file present in your classpath ? May be, i'm not sure about this, but have you changed the case of the folder's name (from oldIDs to oldIds - note the change in case for 'd') ?
The other issue is that the sql update only works when I step the code through the debugger. This is a problem, and I am wondering if it is a known eclipse issue or somthing else.
What happens when you run the program from eclipse as run- java application. Does it throw any error ?
Joined: Apr 18, 2002
AddID is this class.
Inside the IDE it works fine. THe update only works when I step through the debugger, though.
I have a simpler example in the JAVA Beginer's forum just because I thought it was somthing I've overlooked, but this isn't the only code that this is happening to. It only works in IDE's, but not natively.
Ok, Package information has to go.... I removed the package declaration, and the code works external to the Eclipse environment. HOWEVER, Eclipse insists that it has to be there or it won't compile the code.
The name of the package that a class is in is part of the class's name. You cannot run a class from the command line and leave off the package name under any circumstances, because you'll not be calling the class by its proper name. That means, in this case, that the only proper way to invoke the class "oldIds.AddID" is with
is incorrect and cannot be made to work.
Now, there's one more detail: when you invoke this class, Java will look at the classpath to find the oldIds package (i.e., a directory named oldIds) and then in that package, it will look for AddID.class . Therefore, the oldIds directory is the thing that must be on the CLASSPATH, and not the AddID.class file. So, for example, one scenario that works: Say you've got c:\JavaCode\oldIds\AddID.class . Then you could type something along the lines of
X:\> c: C:\> cd \JavaCode C:\JavaCode> java -cp . oldIds.AddID
and, like magic, it will work!
If the C:\JavaCode directory appears on your CLASSPATH environment variable, then
will work from any arbitrary directory. See here for more information on this topic.
Good luck! [ May 15, 2005: Message edited by: Ernest Friedman-Hill ]