How can I make my java app see the class it needs?

106 views Asked by At

I built a little command line program in java. It has a class that gets instantiated and used in the main method. But when I go to compile it at the command line it doesn't 'see' the class it needs to run. It accepts arguments passed in at runtime. I can set it up in Netbeans and it runs beautifully. But I want to be able to use it at the command line. I've tried jar-ing it up, it throws an exception and doesn't see the class that I'm instantiating in main. I took Java in my CS program, but my Prof didn't cover deployment in particular depth.

Any ideas to help me out of my pickle?

Thanks!!

1

There are 1 answers

3
arcy On

Do either of your classes have packages? If they do, they'll have a first statement of "package ", and it makes a difference.

I'm going to assume that at least your Age class does have a package, I'll call the package 'a'.

Let's further assume a main class of "Alex"; it would have an import statement of "import a.age;".

Let's assume you are in a directory named "george".

Your Alex.java file (without a package statement) needs to be in george. Age.java needs to be in a directory underneath george named a.

You can compile your main file with the command "javac Alex", and can run it with "java Alex".

If you tell us more specifics about your problem, we can be more specific about what you need.