Solved

Adding permanent classpath in Unix Environment

Posted on 2011-09-07
13
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

726 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