LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Java Classpath... dear god... (https://www.linuxquestions.org/questions/programming-9/java-classpath-dear-god-283112/)

Jaster 01-27-2005 09:32 PM

Java Classpath... dear god...
 
Ok, I need help with this on windows right now (and I will then try to figure it out on linux and coe back here and ask when I fail ^_^). Ok, I have java installed on my windows partition and it works great. I now have a .jar file (C:\g5jdk\generation5.jar) that I want to add to the java classpath so I can use all the packages and classes in it. So, I went to the enviroment variables section of System in the Control Panel. There was no CLASSPATH variable so a made a new one and set it to ".;C:\g5jdk\generation5.jar" and saved it. Now I try to run a program that imports classes and packages that should be in said .jar file and it won't compile (no class def found). What am I doing wrong here? Any help welcome. Thanks.

drisay 01-28-2005 08:13 AM

did you restart your command prompt? the new settings won't take effect until your next session.

darkRoom 01-28-2005 10:01 AM

ha, ha i like your thread title ;)

Sounds like the classpath isn't a problem now since you can use javac.

To compile the program i guess you are trying 'javac myProg.java' and you are in or give a path to where the .java file is. If not post back with more details

Azzath 02-02-2005 01:25 PM

Hello and thanking everyone helping out there!! You guys have no idea how much of appriciation me and my firend's got for everyone's whose helping out in this site!!
Anyway.....
I need to know if anyone could tell me a way to compile my java programs without giving the javac path....like
/usr/java/j2sdk1.4.2_07/bin/javac HelloWorld.java
.....
i have just installed java. And its a bit of time taking by giving the whole path like i had typed above. Could someone give me an idea to straight forwardly make it to understand the "javac" and "java" commands from the command prompt....i.e
azzath@d_hyper java_programs]$ javac
bash: javac: command not found
without getting this error message...:)
Thanks in advance.

.................................................................................................... ...........................................
anyone who is trying to install java then hopefully this site would help i guess, cuz i got help from this site.
http://home.bredband.no/gaulyk/java/...avaredhat.html

Teoryn 02-02-2005 05:34 PM

If you add a path to the classpath it will always check there. What I did in windows was put '.' in my classpath, then I could navigate to a folder and run the code from there.

Azzath 02-02-2005 06:10 PM

Thank you buddy...
But thats wha i'm trying to do. But i am not sure how to fit in..
export PATH=$PATH:/usr/java/jdk*/bin/ into export PATH=$PATH:/usr/games(which is the "profile" script in the /etc directory)
If yu know anything about it please let me know.
So is that your site..
It looks cool..i havent surfed verymuch into it...but sould be very educational.
Thanx again mate.

Azzath.

drisay 02-03-2005 06:54 AM

just replace "export PATH=$PATH:/usr/games" with "export PATH=$PATH:/usr/games:/usr/java/j2sdk1.4.2_07/bin" in your profile script.

kees-jan 02-03-2005 08:53 AM

Jaster: Are you using an ide? It might be messing up your classpath.

Groetjes,

Kees-Jan

codestorm 02-03-2005 05:04 PM

Ok, given you're doing this for Windows.
(Instructions based on Winblows 2000)
Right-click on "My Computer", select Properties.
Advanced tab, New button in top "User variables for ..." section.
Variable Name: JAVA_HOME
Variable Value: <path to your java install>
e.g. c:\j2sdk1.4.2_04
(not directly to it's bin directory, or anything)
Also it probably couldn't hurt to add it to the PATH variable:
In bottom "System variables" section, find Path in list and press Edit button.
Append path above, with bin dir added, prepended by a ; to Value.
e.g. ;c:\j2sdk1.4.2_04\bin\
Sorry, sure you didn't need these baby steps, but avoids the potential for confusion.

Azzath 02-03-2005 05:39 PM

Drisay thank you....
 
I did edit the /etc/profile file and i still cannot get the javac command to work..
the edited part is as follows..

export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin (OR does it need double quotes such as
export PATH="$PATH:/usr/java/j2sdk1.4.2_07/bin " amd dows the bin finishes with /bin/)

but still the javac is not recognised....

whats the difference in editing as

export PATH=$PATH:/usr/java/sdk*/bin ( which i saw in this site http://home.bredband.no/gaulyk/java/...avaredhat.html )
i can always call the path eg:/user/java/j2sdk1.4.2_07/bin/javac HellowWorld.java

but its always a pain to type in the path...

could some one please tell me if this is the right file to edit which is profile (but in the above site mensioned the person told to edit the /etc/profile.d/java.sh file ( where there wasnt such a file). But i still created a file named java.sh and just gave the line export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin. I know this is not right. I'm sorry, i am not a programmer, but keen in learning java.
But i would like to solve this problem and would some one tell me what might be going wrong ?

kees-jan 02-04-2005 01:36 AM

Azzath:

Let's see... The PATH environment variable contains a list of directories that are searched whenever you type a command. You say that you get "command not found" if you type "javac". So could you please type
Code:

echo $PATH
and post the output? Because after all the changes you have made, there should be some differences :-).

Which shell are you using anyway? Please type
Code:

echo $SHELL
and post the output. If you are using bash (which is the default), then whenever you login, /etc/profile is read and executed. Therefore, if you change the content of /etc/profile (i.e. add commands that change the path), then changes should be visible at your next login. Did you log out and back in after changing?

Sometimes, /etc/profile contains a piece of code that reads all files in /etc/profile.d, and executes them as well. This is distribution dependent. If your /etc/profile indeed has this piece of code, then there should be no difference between editing /etc/profile, and editing any file in /etc/profile.d. But, as said, this depends on this piece of code in /etc/profile.

By typing "export PATH=", you can give the path an entirely new value. $PATH gives you the current (or old value), so
Code:

export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin
basically says "The new value of my PATH should be equal to the old value, plus some stuff concatenated".

If you have only one j2sdk directory, then you can use a * to save you some typing. So, the above could also be written as
Code:

export PATH=$PATH:/usr/java/j2sdk*/bin
If you have only one directory, then this is convenient, because it will figure out the version stuff by itself. If you have several, then this will not work, and you'll be able to use neither. Therefore, I generally do not recommend it.

Quotes can be used for pathnames that contain spaces and some other weird characters. Even so, you probably shouldn't use spaces and weird characters in pathnames anyway. Furthermore, when using quotes, the * trick above doesn't work anymore.

Good luck with your efforts,

Groetjes,

Kees-Jan

jlliagre 02-04-2005 01:55 AM

Try:
Code:

export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin:

Azzath 02-04-2005 05:18 AM

Thanking you kees-jan and the rest who had helped me out with my roblem,

Kees: i initially thought that logging out means come out of "su", then when i swiched my computer on this morning the javac command worked :)
First thing i did was reading ur message and when i went to play with it again by doing an echo $PATH it showed me the path as below, then i tried the javac command and it listed javac and java and it worked well Buddy.

[azzath@d_hyper azzath]$ echo $PATH
/usr/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin/:/usr/java/j2sdk1.4.2_07/bin:/user/java/jdk*/bin/:/home/azzath/bin:/user/java/jdk*/bin/
[azzath@d_hyper azzath]$ echo $SHELL
/bin/bash
I really appreciate for the time and effort you took to explain me all this. Thanking you again.

And also i would like to thank the senior member jlliagre, for his long time effort.
Take care guys.

Regards Azzath.

kees-jan 02-04-2005 05:44 AM

Quote:

[azzath@d_hyper azzath]$ echo $PATH
/usr/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin/:/usr/java/j2sdk1.4.2_07/bin:/user/java/jdk*/bin/:/home/azzath/bin:/user/java/jdk*/bin/
Ideally, you should remove the two entries with stars in them "/user/java/jdk*/bin/", because they don't do anything but confuse things. The entry "/usr/java/j2sdk1.4.2_07/bin" is sufficient and should remain.

Groetjes,

Kees-Jan

Azzath 02-04-2005 07:56 PM

Thank you kees-jan,
But would you please tell me which file should i open to delete that entry in the path?

kees-jan 02-05-2005 08:48 AM

I can't tell you. You've added the entry yourself, so you should know. But it is probably /etc/profile or /etc/profile.d/java.sh

Groetjes,

Kees-Jan

Azzath 02-05-2005 04:01 PM

Yes kees ur right, i forgot all abt the file i created and assigning that path. Thank you soo much buddy.
Appriciate all your help and time.

And one more thing...ru using any ide?I was thinking of using IntelliJ IDEA ...what do u think abt it?
Take care..
Bye!!

jonaskoelker 02-05-2005 08:44 PM

Hi.

I'd think that (in the long term) you'd be happier with emacs, since it's an IDE for (almost) all languages, and you can extend it. It's also a newsreader, web browser, coffeemaker (okay, maybe not) and you can play tetris in it. Basically, why settle for a program that does only java, when you can have a program that does _everything_?

I should have stayed with the tele-marketing ;D

Jonas

kees-jan 02-07-2005 08:06 AM

I'm nut sure about that. Emacs is an excellent example of something I wouldn't recommend to my worst enemy. First, the learning curve is so steep I wouldn't want even him to suffer that much. But if he survives that, he has a tool so powerful he might outperform me :-)

Groetjes,

Kees-Jan

Azzath 02-07-2005 03:57 PM

kees-jan:Thank you buddy!!cuz i am still a crawler in java, i think i better take your advice :)

jonaskoelker:Thank you to you jona.. for your reply on my matter. I think i will use an ide which will give me more help until for sometime. Then when i am sure of what i'm doing then i will switch to emacs.
Take care.
Azzath.


All times are GMT -5. The time now is 10:26 PM.