?
Solved

Adding permanent classpath in Unix Environment

Posted on 2011-09-07
13
Medium Priority
?
369 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 1000 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:Gurvinder Pal Singh
Gurvinder Pal Singh earned 1000 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:Gurvinder Pal Singh
ID: 36500506
In unix you need to replace ; with :
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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:Gurvinder Pal Singh
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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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