943,737 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1375
  • Java RSS
Oct 29th, 2007
0

classpath errors

Expand Post »
I've been trying to work out this error with packages, changing the classpath name in a number of different ways (using set, declaring it in the javac command), but I always get the following errors when I try to compile the following code:
import kalut.*;
import java.lang.Math.*;

public class Koetesti {
public static void main(String[] args) {
Koe a = new Koe();

a.x = 5;

System.out.println("a.x: " + a.x);
}
}

ku-hupnet193-75:~/lahdekoodit/javaohj dshaw$ javac Koetesti.java
Koetesti.java:1: package kalut does not exist
import kalut.*;
^
Koetesti.java:6: cannot access Koe
bad class file: ./Koe.java
file does not contain class Koe
Please remove or make sure it appears in the correct subdirectory of the classpath.
Koe a = new Koe();
^
2 errors

It seems as if the it's looking for the class file in the current direction, despite the fact that I have the classpath set to ./classes (more specifically, /Users/dshaw/lahdekoodit/javaohj/classes). It almost seems like I have some stupid error like incorrect case but I don't, still nothing helps. What am I not doing?

Edit: I realised that it's the .java file, not the .class file, that the compiler uses for packages. I also noticed that the compiler wants the package files to be in a directory that is named after the package, in my case, in the directory "kalut". But for some reason it only works when folder "kalut" is in the current working directory, not the "./classes" directory as I have the classpath defined. Any reasons for this?
Last edited by gerik; Oct 29th, 2007 at 10:32 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gerik is offline Offline
7 posts
since Jun 2006
Oct 29th, 2007
0

Re: classpath errors

You may have not set the environment variable correctly. Check the manual pages for your OS
javac(1) - Manual page [ Solaris™ Operating System | Microsoft Windows ].
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Oct 29th, 2007
0

Re: classpath errors

you need to add the current directory to the classpath as well.
It's not there by default on most modern operating systems for security reasons.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Oct 29th, 2007
0

Re: classpath errors

How do you add the current directory to the classpath?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gerik is offline Offline
7 posts
since Jun 2006
Oct 29th, 2007
0

Re: classpath errors

javac -cp .\;.\classes Koetesti.java
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Learning Tools
Next Thread in Java Forum Timeline: Clear the console screen





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC