Link to home
Start Free TrialLog in
Avatar of SnowCrash89
SnowCrash89

asked on

Java Package Classes Cannot Find Symbol

Hi,
I am creating a Java program in a package called jblog. This consists of the main class BlogServer which needs to create objects of other classes in the same package.

I have stored all the Java source files for my package in a <path to source directory>/jblog
and am compiling these to the directory <path to classes directory>/jblog

When I attempt to compile the main java class - BlogServer I get Symbol Not Found errors for some of the other classes in my directory, the BlogServerInterface class (as well as other classes):

# javac -d ../../classes/jblog/ BlogServer.java
BlogServer.java:9: cannot find symbol
symbol: class BlogServerInterface
public class BlogServer implements BlogServerInterface

Both my BlogServer class and BlogServerInterface class are in the same jblog/ directory and have the package jblog line on the first line of the source file. Why can't the compiler find the BlogServerInterface class?

Thanks.

Avatar of Mick Barry
Mick Barry
Flag of Australia image

you need to specify the classpath

javac -d ../../classes/jblog/ -classpath ../../classes BlogServer.java
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SnowCrash89
SnowCrash89

ASKER

Ah, that worked, so when you're specifying a package name in your java files you have to use the -classpath parameter when compiling?
no, you need to specify the classpath if it needs to find dependant classes
the classpath is used to lookup classes
That's strange though, I've managed to compile succesfully a class with dependant classes without having to specify the classpath. Anyway problem solved.
Thanks.