aspose file tools*
The moose likes Beginning Java and the fly likes Class Path in linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class Path in linux" Watch "Class Path in linux" New topic
Author

Class Path in linux

pratik gaurav
Greenhorn

Joined: Oct 04, 2012
Posts: 16

How to set the Classpath in linux ?
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1512
    
    5

pratik gaurav wrote:How to set the Classpath in linux ?

On Linux, you can set environment variable named CLASSPATH and assign values to it.

However, generally, it is not recommended to set this environment variable unless you need all Java applications on your environment to use specific classes defined in CLASSPATH.

A better option would be to use -cp or -classpath argument while compiling/executing Java codes.

HIH.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 905
    
    5
A sidenote: under Unix including Linux the separator character is :

Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

Hi pratik gaurav ,

Would you like to set the class path on an individual user level or on global environment level ( available to all users including root ) ?


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

opent the file /etc/bashrc with your favourite text editor and add the following lines to the top of the file

Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 905
    
    5
I make wrapping scripts for the different versions like javac15, java16, javap17, and put them on PATH and invoke from them the corresponding java executables with their full path name.
I found this to be a convenient way of peaceful coexistence of different Java versions.

That is an argument against a common global setting.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1512
    
    5

Ivan and Saif,

You are simply adding paths of Java utilities (java, javac etc.) to system's PATH variable.

It has nothing to do with CLASSPATH. The class path can be set by ways mentioned in my previous post (defining CLASSPATH variable, or adding -cp or -classpath argument to Java).

HIH.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Only use the -cp option (which is the same as the -classpath option).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Always use the -cp option (which is the same as the -classpath option).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class Path in linux