[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Adding permanent classpath in Unix Environment

Posted on 2011-09-07
13
Medium Priority
?
371 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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:
This video teaches viewers about errors in exception handling.
Suggested Courses

650 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