Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ubuntu Server CLASSPATH not working

 
Ampage Grietu
Greenhorn
Posts: 2
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that I finished and compiled on one computer in our lab. It is saved under my username for Ubuntu Server. It imports a package that compiled fine on that computer, as well as most others. However, that lab is currently in use so I am in another one. I logged into my account and tried compiling the same program, and it is failing to import the package. I opened up the .bashrc file and lo, the CLASSPATH is still set and the packages have not moved. Is there an explanation as to why this is happening and how it could be fixed?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

If you type:

echo $CLASSPATH

then what is printed; is it the correct classpath that you expected? If not, then the setting in .bashrc is not being used for some reason; you'd have to dig around a little in the system to find out why not.
 
Ampage Grietu
Greenhorn
Posts: 2
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I echo the CLASSPATH it indeed shows the correct path.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, then you'll have to be a little more specific. What does the content of the CLASSPATH look like? Are there no typos, no spaces that should not be there, etc.? Note that on Ubuntu, directories and jar files in the CLASSPATH should be separated with colons ":" and not semi-colons ";" as on Windows. (If you use semi-colons, it will not work).
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, don't forget that the classpath entries refer to where the package roots are located.

If you specify "CLASSPATH=/var/lib/myapp/classes", then the actual location of the classfile for com.javaranch.testproject.Helpme MUST be /var/lib/myapp/classes/com/javaranch/testproject/Helpme.class
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I advise against setting CLASSPATH in .bashrc, doing so will almost guarantee that you will have some unwanted surprises. It is better to set it within a script taht passes the value as the -cp entry on the java command line itself. Also if you do that you can use ps to view the command line used to run the java executable to verify that you got it correct (which is handy if a script start the app)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic