Solved

Adding permanent classpath in Unix Environment

Posted on 2011-09-07
13
358 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now