This program runs OK after a '.jar' file is created. However, during development I would prefer to run w/o the additional step of having to create a new jar before every test cycle. Unfortunately the 'package' statement must be commented out for that to succeed.
What do I need to do differently during testing to execute the .class version of my 'main' program ? I've tried every combination of -cp etc. that could possibly work, until nothing makes sense to me anymore.
I'm assuming that your development environment is cmd.exe and notepad on Windows. One alternative, of course, is to use something a bit fancier, like the Eclipse IDE (www.eclipse.org). But it is nice to get your feet wet with simple tools first.
Anyway, let's say your directory tree looks like this:
Note that period (.) after the -classpath flag; that means "the current directory." In general, the class path should include the directories in which the top-level package directories of your classes appear. The default setting for the class path includes ".", so if your environment variable CLASSPATH is unset -- not set at all -- you can shorten the above to just
Bingo!! You clearly typed java subDirA.subDirB.MyPgm too many times I type java subDirA\subDirB\MyPgm then Finally, I see/do as you advise, and of course it works
Can you explain why/how Java navigates from PROJECTS to locate files in subDirB? I would have never known to use the 'dot' format w/o your advice.
I'm modifying/extending Thinlet examples which deploy from ...thinlet\demo I've used Eclipse with Ant build.xml for JSP/Struts projects for about a yr, but for this effort, I've simplified to cmd.exe and Notepad. I've never noticed the 'dot' format in a commandline before.
A big ThankS for the help !! btw - have worked w/James Owens in Dallas using JESS, busns rules etc
The "java" command takes the name of a class -- not a class file. Remember that the package name is also part of the name of the class. Thus, if your class is "Grep" in package "foo.bar", then the actual class name is "foo.bar.Grep" This is what you type to run it. (java foo.bar.Grep) Note that you do not type java foo/bar/Grep.class
This is also why the directory structure must match the package structure -- to find the .class file, the default ClassLoader simply substitutes '.' in the class name with the file separator for your OS ('/', '\', or even ':' (historically)). Then, is appends the ".class" extension and goes looking for that file. If it can;t find it -- ClassNotFoundException.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
author and iconoclast