LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-27-2005, 09:32 PM   #1
Jaster
Member
 
Registered: Jun 2004
Posts: 105

Rep: Reputation: 15
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.
 
Old 01-28-2005, 08:13 AM   #2
drisay
Member
 
Registered: Sep 2004
Distribution: Slackware 10
Posts: 167

Rep: Reputation: 30
did you restart your command prompt? the new settings won't take effect until your next session.
 
Old 01-28-2005, 10:01 AM   #3
darkRoom
Member
 
Registered: Mar 2004
Location: Valencia, espaņa
Distribution: Slack, Gentoo, Custom
Posts: 162

Rep: Reputation: 30
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
 
Old 02-02-2005, 01:25 PM   #4
Azzath
Member
 
Registered: Jan 2005
Location: Russia
Distribution: Mandrake, CentOS
Posts: 138

Rep: Reputation: 16
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
 
Old 02-02-2005, 05:34 PM   #5
Teoryn
LQ Newbie
 
Registered: Jan 2004
Location: Ohio
Distribution: Gentoo
Posts: 26

Rep: Reputation: 15
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.
 
Old 02-02-2005, 06:10 PM   #6
Azzath
Member
 
Registered: Jan 2005
Location: Russia
Distribution: Mandrake, CentOS
Posts: 138

Rep: Reputation: 16
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.
 
Old 02-03-2005, 06:54 AM   #7
drisay
Member
 
Registered: Sep 2004
Distribution: Slackware 10
Posts: 167

Rep: Reputation: 30
just replace "export PATH=$PATH:/usr/games" with "export PATH=$PATH:/usr/games:/usr/java/j2sdk1.4.2_07/bin" in your profile script.
 
Old 02-03-2005, 08:53 AM   #8
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

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

Groetjes,

Kees-Jan
 
Old 02-03-2005, 05:04 PM   #9
codestorm
LQ Newbie
 
Registered: Feb 2005
Location: Newcastle, Australia
Distribution: DamnSmallLinux
Posts: 2

Rep: Reputation: 0
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.
 
Old 02-03-2005, 05:39 PM   #10
Azzath
Member
 
Registered: Jan 2005
Location: Russia
Distribution: Mandrake, CentOS
Posts: 138

Rep: Reputation: 16
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 ?
 
Old 02-04-2005, 01:36 AM   #11
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
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
 
Old 02-04-2005, 01:55 AM   #12
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Try:
Code:
export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin:
 
Old 02-04-2005, 05:18 AM   #13
Azzath
Member
 
Registered: Jan 2005
Location: Russia
Distribution: Mandrake, CentOS
Posts: 138

Rep: Reputation: 16
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.
 
Old 02-04-2005, 05:44 AM   #14
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
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
 
Old 02-04-2005, 07:56 PM   #15
Azzath
Member
 
Registered: Jan 2005
Location: Russia
Distribution: Mandrake, CentOS
Posts: 138

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set CLASSPATH of java in Linux? vanhelsing Programming 1 08-23-2004 06:16 AM
Dear god, help with 'make' command in SuSE 9.1 jihadcman Linux - Distributions 13 07-13-2004 02:11 AM
setting java classpath... brutal_brad Linux - Newbie 7 09-21-2003 02:52 PM
How to set classpath for java jolly Linux - Software 3 04-22-2003 10:02 PM
ClASSPATH variable for Java oulevon Linux - General 1 02-28-2001 08:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration