Java: import cs1.keyboard in linux

algernon

Weaksauce
Joined
Oct 6, 2003
Messages
64
hi,
im new to java and i am used to doing my coding in my java class in Jcreator.
I understand how to set up cs1.keyboard in jcreator,
but i need to do my homework and code java at home, but i run linux at home and jcreator doesn't work with linux. and also i want to learn how to do it out of Jcreator.

i just made this simple program to see if the keyboard class would work
Code:
import cs1.Keyboard;
public class AYBABTU{

public static void main (String[] args){
System.out.println("How many bases do you have?");
int bases;
bases = Keyboard.readInt();
System.out.println("All Your " + bases);
System.out.print (" Bases Are Belong to US");
}
}

i compile the program and im getting

"AYBABTU.java:1: package cs1 does not exist"

where can i get this package and how do i set it up to use it in linux.
 
i'm guessing it's a package given to you by your teacher - look in your main source folder in jcreator and you'll find one called "cs1" (either that or it's in a .jar file). either the .jar or the folder need to be in your classpath - best bet is to put either in the same folder you're trying to compile (or run) from, then run the same command again. if that doesn't work, make sure you've got "." in the CLASSPATH environment variable (ie the current directory).

You might want to look at using eclipse as your editor - it's fully cross-platform (runs very nicely under X) and makes life far easier.

EDIT : just a small point - it should be "all your x base are belong to us" ;)
 
ok, i have the cs1.jar file and put it in the same directory im compliling in.
it still produces the same error

what do you mean by "make sure you've got "." in the CLASSPATH environment variable (ie the current directory)."
 
Assuming you're using javac, just type

Code:
javac -classpath . AYBABTU.java

For some reason I remember it being shorter then that though...it's been awhile though, so I could be wrong.
 
Jason Isom said:
Assuming you're using javac, just type

Code:
javac -classpath . AYBABTU.java

For some reason I remember it being shorter then that though...it's been awhile though, so I could be wrong.
the switch can be either -cp or -classpath
 
thanks for everyone's help so far, but im still getting this error
Code:
bash-2.05b$ javac -classpath . AYBABTU.java
AYBABTU.java:1: package cs1 does not exist
import cs1.Keyboard;
           ^

i have the "cs1.jar" file in the same directory also. i also tried renaming the file to just "cs1" but it still doesn't work. any ideas
 
Directory should have your AYBABTU.java file and your cs1.jar file

While in the same directory, execute the following command:
Code:
javac -classpath ".;cs1.jar" AYBABTU.java

If there are errors, post them.

--KK
 
Code:
bash-2.05b$ cd ./Desktop/test
bash-2.05b$ ls
AYBABTU.java  AYBABTU.java~  cs1.jar  test.java  test.java~
bash-2.05b$ javac -classpath ".;cs1.jar" AYBABTU.java
AYBABTU.java:1: package cs1 does not exist
import cs1.Keyboard;
           ^
AYBABTU.java:7: cannot resolve symbol
symbol  : variable Keyboard
location: class AYBABTU
bases = Keyboard.readInt();
        ^
2 errors
bash-2.05b$

same errors
also i booted up in windows and used the same cs1.jar file and it worked fine. so the cs1 file isn't corrupt or anything
 
some things to try:

leave out -classpath and just do the following with your source and .jar file in the same folder(although it seems you already have).

Code:
javac ./*.java

also, try the following to look for clues to your problem

Code:
javac -verbose ./*.java

alternately, you can toss your .jar file into the following folder and it would probably work
Code:
$JAVA_HOME/jre/lib/ext/


--KK
 
sweet, i tossed the jar file in that directory and viola. it compiled flawlessy and the program works fine.

thanks KK
 
gg :)

You should still fixup your classpaths when you have time though as putting everything in lib/ext isnt always the best thing to do

--KK
 
Just to update we all didnt rtfm :p and I feel silly for missing this. colons should be used in your classpath rather than semicolons:

Code:
javac -classpath .:cs1.jar AYBABTU.java

--KK
 
Back
Top