If I compile a class using 'javac -d' and the class goes to a package, how do I run that class with the 'java' command? It doesn't seem to work in the source directory or when I go into the package directory. Thanks. Paul
Paul, Can you please post exactly what you're typing to run your classes (your java command after you've compiled)? It would also be helpful to see what directory you're running it from and what directory the classes or package is in. Finally - are you trying to run it in a jar or just as the classes? Thanks -
Greg Ostravich - SCPJ2
Joined: Mar 15, 2000
My package is 'keypad.data.jaxb'. I compile my class in my C:\test directory like this - javac -d DataAccess.java It contains a main() method so to run it I've tried all four of the following from the same directory I compiled from. java DataAccess java -d DataAccess java keypad.data.jaxb.DataAccess java -cp C:\test\keypad\data\jaxb DataAccess All of them have given me a noClassFound exception. Thanks for your help.
Originally posted by Paul Keohan: My package is 'keypad.data.jaxb'.
By this, I assume you mean that you have the statement: package keypad.data.jaxb; at the beginning of your java file.
I compile my class in my C:\test directory like this - javac -d DataAccess.java
Something is missing there - there needs to be some directory after the "-d". Maybe you mean: javac -d c:\test DataAccess.java or javac -d . DataAccess.java In that case, javac is going to put your class in its package in the "-d" directoroy. That is, you will end up with: c:\test\keypad\data\jaxb\DataAccess.class
It contains a main() method so to run it I've tried all four of the following from the same directory I compiled from. java DataAccess java -d DataAccess java keypad.data.jaxb.DataAccess java -cp C:\test\keypad\data\jaxb DataAccess
The full name of a class is the package name + class name. That's what you have to give to the java command. That's the keypad.data.jaxb.DataAccess there at the end. It's going to convert that whole thing to a directory structure plus class file, in this case keypad\data\jaxb\DataAccess.class. It looks thru classpath to find that. So classpath has to point to the "top of the package tree". That's why your classpath has to include C:\test rather than anything else. So when the java command puts it all together, it will load C:\test + \keypad\data\jaxb\DataAccess.class. Hopefully you will get something good, or at lease a different exception then