Re: Anyone use variables to shorten classpath declaration?



snoopy_@xxxxxxxxxx wrote:

Anyone use variables to shorten classpath declaration? For example,
if I want to point to /opt/myclasses/testpackage.jar, could I do the
following?

update .profile to include

PACKAGE_DIR=/opt/myclasses

CLASSPATH=$PACKAGE_DIR/testpackage.jar
export CLASSPATH

Yes, that will work.



The reason I am asking is because I am trying to troubleshoot an issue
where an application failed to find some jar files, and I found that
one profile sourced another, but the variable it uses as a shortcut
isn't defined at the time the CLASSPATH is defined, however, if I
check the path after all the source files are picked up it looks right
via "echo $CLASSPATH" because I have since defined PACKAGE_DIR.

For example, the definition aboe is switch to look like:

CLASSPATH=$PACKAGE_DIR/testpackage.jar
export CLASSPATH

PACKAGE_DIR=/opt/myclasses

No, that won't work. If you use a variable as part of another variable
definition you get its contents at the time you use it. Try it manually and see
what you get.

Variables don't record that they are dependent on other variables. When you use
one variable in the definition of another all that happens is that the current
value of that variable is inserted. If it has no current value (isn't defined)
then nothing is substituted. Your resulting CLASSPATH will be
"/testpackage.jar". No amount of changing $PACKAGE_DIR after the fact will
alter that.


I know it's a strange question, but I'm pulling out my hair trying to
figure out why we had CLASSPATH issues with our system.

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@xxxxxxxxxxxx
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
.



Relevant Pages

  • MSSQL2000 jdbc driver on UNIX --- (again)
    ... Yes, it was classpath problem. ... I revised my .profile and then it can work. ... My environment setting are showed as below: ... But can not show anything on UNIX. ...
    (microsoft.public.sqlserver.jdbcdriver)
  • RE: CLASSPATH in .profile not used.
    ... Ensure your HOME directory setting within your OMVS Segment is the same ... CLASSPATH in .profile not used. ... what environment variables have been set by your .profile. ... I have defined the CLASSPATH variable in my .profile file. ...
    (bit.listserv.ibm-main)
  • Re: MSSQL2000 jdbc driver on UNIX --- (again)
    ... CLASSPATH in .profile. ... David Huang ... $SHELL ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Anyone use variables to shorten classpath declaration?
    ... Anyone use variables to shorten classpath declaration? ... where an application failed to find some jar files, ... one profile sourced another, but the variable it uses as a shortcut ...
    (comp.lang.java.help)
  • Re: Converting Java batch file from windows to unix format
    ... Lans Redmond wrote: ... You can set the classpath on the javac command in exactly the ... University of Leicester, Leicester, LE1 7RH, UK ...
    (comp.unix.shell)