Solved

Adding permanent classpath in Unix Environment

Posted on 2011-09-07
13
365 Views
Last Modified: 2012-05-12
Hi Experts...
I have java file which is looking for new jars and therefore i need to set new classpaths and as well need to retain the old ones too.
So how would i add /paths/lib/servlet.jar to the existing list of class paths.
Please help...
0
Comment
Question by:gaugeta
  • 4
  • 3
  • 3
  • +1
13 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 250 total points
ID: 36500484
if you have your perevious CLASSPATH as environemt variable, then you can do like this:

first check

echo $CLASSPATH

then do like this

setenv CLASSPATH ${CLASSPATH}:/paths/lib/servlet.jar

in some other shell it may be not setenv

which system and shell are you using ?

0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 250 total points
ID: 36500502
like this

set CLASSPATH=%CLASSPATH%;.
set Cpath=/paths/lib/servlet.jar
javac -classpath %Cpath%;. className
java -cp %Cpath%;. className

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36500506
In unix you need to replace ; with :
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:gaugeta
ID: 36500523
@for_yan:I am using TC Shell.Thanks for the reply.

@gurvinder372:Thanks for the reply.
So i would need to do follow the below steps in unix right.
set CLASSPATH=%CLASSPATH%;.
set Cpath=/paths/lib/servlet.jar
javac -classpath %Cpath%:. className
java -cp %Cpath%:. className
But i need this to be added to permanent classpath so that i wouldn't have to include this path every time.
Please help...

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36500529
You can store this script into a shell script file and run it everytime.

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36500539
In TC shell I guess
setenv should be working
so this should be fine;
try it:

echo $CLASSPATH

setenv CLASSPATH ${CLASSPATH}:/paths/lib/servlet.jar
0
 

Author Comment

by:gaugeta
ID: 36500565
@all:Thanks for the reply.I will try these and get back if i face any issues.
Thanks again...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36501044
>>Adding permanent classpath in Unix Environment

I work permanently in a Unix environment and can't think of an occasion when i'd consider it a good thing to set a permanent classpath as

a. it's unnecessary
b. it can cause problems

Just set it before you need it for that occasion/session
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36501071
>>if you have your perevious CLASSPATH as environemt variable, then you can do like this:

While that's correct, i wouldn't do that either as it's error prone: if it somehow gets executed several times, you'll just get a massive env var with multiple redundancies. Better to source a script with simply the correct classpath you need, without concatenation
0
 

Author Comment

by:gaugeta
ID: 36502397
@CEHJ:The above solution provides classpath whichwill be alive for only a session.
Its an absolute requirement that i have a permanent classpath.How do i achieve the same.
Please help...
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36502446
You need to add the setenv command to your .cshrc file then it will be set every time you login or open new shell.
Alternatively you can make a short script to start your java program whjere in the first command you set CLASSPATH and in the second command start your java process
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36502502
>>Its an absolute requirement that i have a permanent classpath

I'm not sure why. What are you going to do for the next application that might require a completely different classpath? If you keep appending to a permanent classpath, you'll get a mess that's unscalable. You just need to ensure that the correct classpath is set for the application - that's nothing to do with permanency
0
 

Author Comment

by:gaugeta
ID: 36502782
@CEHJ:Usually there is a practice in this project to un-jar all class files then creating a custom jar which will contain all class files.
Its weird but thats how it is.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question