Solved

Java Package Classes Cannot Find Symbol

Posted on 2010-11-29
5
750 Views
Last Modified: 2012-05-10
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.

0
Comment
Question by:SnowCrash89
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 34235697
you need to specify the classpath

javac -d ../../classes/jblog/ -classpath ../../classes BlogServer.java
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 34235699
that may actually be:


javac -d ../../classes/jblog/ -classpath ../../classes/blog BlogServer.java

its unclear if you are using packages or not
0
 

Author Comment

by:SnowCrash89
ID: 34235766
Ah, that worked, so when you're specifying a package name in your java files you have to use the -classpath parameter when compiling?
0
 
LVL 92

Expert Comment

by:objects
ID: 34235820
no, you need to specify the classpath if it needs to find dependant classes
the classpath is used to lookup classes
0
 

Author Comment

by:SnowCrash89
ID: 34235844
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.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question