• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

CLASSPATH question in Linux SuSE

 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short time ago I changed my system to Linux,
doing my Javaranch assignments now there.
To successfully import the jar file "JavaRanchCommon.zip" I need to set the CLASSPATH accordingly.
I tried it like this this in my
/etc/profile.local:
JAVA_HOME=/usr/java/j2sdk1.4.1_01
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=$JAVA_HOME/jul/JavaRanchCommon.zip
But my Java program is not able to find the file. (The mistake is certainly not in the program, because it is running fine on my Windows System).
Does anybody know what I am doing wrong?
Thanks a lot,
Juliane
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried to put it in the (hidden) .profile file which resides in yout home directory?
You can do: . ~/.profile (note the dots) to try it.
After logging out and back in again it should be working.
-Barry
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I tried it like this this in my
/etc/profile.local:
JAVA_HOME=/usr/java/j2sdk1.4.1_01
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=$JAVA_HOME/jul/JavaRanchCommon.zip


Hang on! Do you mean the above literally?
If yes, you have to use export at the beginning of each of those three definitions.
I just tried out the /etc/profile.local file and it does get invoked during a login. Funny, I always used a .profile in my home directory for that purpose.
Anyway, check that you have used the export command in your file, and check with echo $JAVA_HOME etc. that the definitions are visible after a login.
I would also reverse the order of the PATH definition:
export PATH=$JAVA_HOME/bin:$PATH to make sure that it really is the 1.4 compiler that gets used.
-Barry
[ December 28, 2002: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also, make sure you have permission to "execute" the javaranch.jar file... i know this sounds trivial, but if you downloaded or copied the javaranch file as "root" and then try to use it as "jul", you will not be able to if "jul" does not have permission.
the easiest way to do this is to "chown" the file to "jul"...
or, you could make "jul" part of a group, then "chgrp" the file to the new group name and then "chmod g+x" the file so the group can execute the .jar file.
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh... like barry said, you have to "export" your settings in the .profile...
however, you can just put a line at the end of the file to export everything
EXPORT JAVA_HOME PATH CLASSPATH...
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greg, is read access to the jar file not enough? It's not an executable jar file we have here. (I'm too lazy at the moment to switch over to Linux to try it).
Also, I prefer to export every definition (even multiple redefinitions) because I often forget to do it at the end of the file. However, is there any real efficiency advantage to do it just once as you have suggested?
-Barry
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i do not know if you really need execute access or not... i was just giving an idea. i have been configuring my machine the past few days and have run into problems with different permissions.
so, juian, just chown or chgrp so that "jul" can have access to the .jar file.
as for exporting every line vs. one export at the end of the file - i do not think there is an efficiency issue. i just like to export everything at the end becuase i keep all the classpath environment variables on seperate lines... use tomcat, mysql, java, c++, ada, etc. - so it is just easier for me to put a new CLASSPATH=$CLASSPATH:... line when i add something new (i started doing this in windows because my autoexec.bat file was getting very ugly).
 
juliane gross
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greg and Barry,
thank you very much for your help!
Funny things happened:
1) I put export in front of every one of my three lines.
result:
the command echo $CLASSPATH found it correctly.
When I started my program, I did not get the missing jar file error message, but instead:
NoClassDefFoundError.
This error I got with any program I tried to run,also from those not using the import command.
2) I changed my profile.local back to my very first way (no export) and no CLASSPATH at all, to make sure that java was running fine again. It did, but did not know the jar file of course.
3) I tried JAVA_HOME and PATH without export and CLASSPATH with export.
result: same like 1)
4) I tried again three lines (JAVA_HOME, PATH, CLASSPATH) without ANY export:
result:
java is running fine.
echo $CLASSPATH doesn't find something, but:
my program is running!!!
My mistake when I posted my question, was:
I did not do a proper new login. I guess if I would have done, the program had been running okay.
Now I am curious about this:
1) why do some people use export and what for?
2) why isn't the CLASSPATH found with the echo command but the program working fine?
Well, I am happy about being able to continue with coding, finally, but if any of you knows about this mistery, would just be interesting to know!
Juliane
p.s.
I just see that greg had added another post;
Just adding this detail: I had set permissions for the jar file in the first place, so I think that had not been the problem.
p.p.s
the torture DOES NOT stop:
now I get the jar file not found message while compiling. BUT the program with the jar file in it runs nonetheless.

[ December 29, 2002: Message edited by: juliane gross ]
[ December 29, 2002: Message edited by: juliane gross ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Juliane, what do you get when you type the following commands?
which javac
which java
java -version
echo $PATH
echo $CLASSPATH
echo $JAVA_HOME
ls -l <your path to the JR zip file>
And what version of Suse are you using and what Window Manager (kde, gnome,...)
BTW. export means to make the environment variable and its definition available to all subprocesses of the process that originally defines it.
-Barry
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have just found (on my Suse 8.1) system a directory /etc/java. In it there is a file java.conf that enables a switch between different java versions. Do you have the same file? Is it the cause of your problems? I wonder.
I have just now set the file contents to:
Priority : 40
Vendor : Sun
Version : 1.4.1
Devel : True
JAVA_BINDIR = /usr/java/j2sdk1.4.1_01/bin
JAVA_ROOT = /usr/java/j2sdk1.4.1_01
JAVA_HOME = /usr/java/j2sdk1.4.1_01
JRE_HOME = /usr/java/j2sdk1.4.1_01/jre
JDK_HOME = /usr/java/j2sdk1.4.1_01
SDK_HOME = /usr/java/j2sdk1.4.1_01
JAVA_LINK = /usr/java/j2sdk1.4.1_01
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just downloaded JavaRanchCommon.zip and set things up.
I found that I needed to set CLASSPATH to:
/cattledrive/lib/JavaRanchCommon.zip:. (note the :. at the end and the directory is arbitrarily chosen)
I was able to compile and run a simple program which imported com.javaranch.common.*; and created and printed an ADate instance.
-Barry
[ December 29, 2002: Message edited by: Barry Gaunt ]
 
juliane gross
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry, you are incredible - thank you so much!!!

I also use Suse 8.1.
I found the java config file, and set everything
accordingly.
Everything works fine now.
Isn't this forum great?
I love the java ranch, and hope to be able to contribute some help one day, too.
Juliane
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Happy to help. Contributing is easy, just jump in. If you are wrong someone will tell you so, and you learn something from it too.
(What I have to learn is when NOT to jump in sometimes )
-Barry
 
What are your superhero powers? Go ahead and try them on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic