a java classpath question

Discussion in 'Java' started by zyng, Dec 28, 2012.

  1. zyng

    zyng Guest

    Hi:

    My Java program is started by using somebody's shell script. Inside his script:

    java -classpath his_lib/'*' Main

    However, I also wish to set Java's classpath for my code to work and I am not allowed to change his script.(He: actually is a company. My program is running inside this company's main frame).

    So when JVM starts, the true classpath is my_lib/'*';his_lib/'*'. Is that possible to do?

    Thank you.
    zyng, Dec 28, 2012
    #1
    1. Advertising

  2. zyng

    Arne Vajhøj Guest

    On 12/28/2012 12:07 PM, zyng wrote:
    > My Java program is started by using somebody's shell script. Inside
    > his script:
    >
    > java -classpath his_lib/'*' Main
    >
    > However, I also wish to set Java's classpath for my code to work and
    > I am not allowed to change his script.(He: actually is a company. My
    > program is running inside this company's main frame).
    >
    > So when JVM starts, the true classpath is my_lib/'*';his_lib/'*'. Is
    > that possible to do?


    No.

    For that to be possible his shell script should have used
    a variable that you could have set.

    I would copy his shell script and modify it.

    Arne
    Arne Vajhøj, Dec 28, 2012
    #2
    1. Advertising

  3. zyng

    zyng Guest

    OK. Thanks. But I can not make it work. In the script:

    his_lib=/a/b
    my_lib=/c/d

    java -classpath $his_lib/'*' Main //old script and it works

    java -classpath $his_lib/'*';$my_lib/'*' Main //not working, saying /c/d/*: No such file or directory

    Confused.
    zyng, Dec 28, 2012
    #3
  4. zyng

    zyng Guest

    On Friday, December 28, 2012 1:44:13 PM UTC-5, zyng wrote:
    > OK. Thanks. But I can not make it work. In the script:
    >
    >
    >
    > his_lib=/a/b
    >
    > my_lib=/c/d
    >
    >
    >
    > java -classpath $his_lib/'*' Main //old script and it works
    >
    >
    >
    > java -classpath $his_lib/'*';$my_lib/'*' Main //not working, saying /c/d/*: No such file or directory
    >
    >
    >
    > Confused.


    Wow, this is working:
    java -classpath $his_lib/'*':$my_lib/'*' Main //using ":" not ";" to separate

    (Obviously, I am on Linux.)

    But, this document is using ";", not ":"
    http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
    zyng, Dec 28, 2012
    #4
  5. zyng

    Arne Vajhøj Guest

    On 12/28/2012 1:44 PM, zyng wrote:
    > OK. Thanks. But I can not make it work. In the script:
    >
    > his_lib=/a/b
    > my_lib=/c/d
    >
    > java -classpath $his_lib/'*' Main //old script and it works
    >
    > java -classpath $his_lib/'*';$my_lib/'*' Main //not working, saying /c/d/*: No such file or directory
    >
    > Confused.


    On *nix I think classpath elements is separated by : not ;.

    Arne
    Arne Vajhøj, Dec 28, 2012
    #5
  6. zyng

    Arne Vajhøj Guest

    On 12/28/2012 1:48 PM, zyng wrote:
    > On Friday, December 28, 2012 1:44:13 PM UTC-5, zyng wrote:
    >> OK. Thanks. But I can not make it work. In the script:
    >> his_lib=/a/b
    >> my_lib=/c/d
    >>
    >> java -classpath $his_lib/'*' Main //old script and it works
    >>
    >> java -classpath $his_lib/'*';$my_lib/'*' Main //not working, saying /c/d/*: No such file or directory
    >>
    >> Confused.

    >
    > Wow, this is working:
    > java -classpath $his_lib/'*':$my_lib/'*' Main //using ":" not ";" to separate
    >
    > (Obviously, I am on Linux.)
    >
    > But, this document is using ";", not ":"
    > http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html

    ^^^^^^^

    It says Windows.

    You want:

    http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/classpath.html

    Arne
    Arne Vajhøj, Dec 28, 2012
    #6
  7. zyng

    Lew Guest

    zyng wrote:
    > zyng wrote:
    >> OK. Thanks. But I can not make it work. In the script:
    > > his_lib=/a/b


    Forward slash hints you might be using a *nix style system.

    >> my_lib=/c/d

    >
    >> java -classpath $his_lib/'*' Main //old script and it works


    "works": Meaning it picks up all JARs in that directory, yes?

    >
    >> java -classpath $his_lib/'*';$my_lib/'*' Main
    >> //not working, saying /c/d/*: No such file or directory
    >> Confused.

    >
    > Wow, this is working:
    >
    > java -classpath $his_lib/'*':$my_lib/'*' Main //using ":" not ";" to separate
    >
    > (Obviously, I am on Linux.)


    Obvious to whom?

    > But, this document is using ";", not ":"
    >
    > http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html


    What was that URL again?

    .... windows/ ...

    --
    Lew
    Lew, Dec 28, 2012
    #7
  8. zyng

    Roedy Green Guest

    On Fri, 28 Dec 2012 09:07:39 -0800 (PST), zyng <>
    wrote, quoted or indirectly quoted someone who said :

    >However, I also wish to set Java's classpath for
    > my code to work and I am not allowed to change his script.
    >(He: actually is a company. My program is running inside this company's main frame).


    Things to try:

    1. classpath set in jar manifest.

    2. custom classloader

    3. setting system property (I have not tried this).

    --
    Roedy Green Canadian Mind Products http://mindprod.com
    Students who hire or con others to do their homework are as foolish
    as couch potatoes who hire others to go to the gym for them.
    Roedy Green, Dec 29, 2012
    #8
  9. zyng

    Roedy Green Guest

    On Fri, 28 Dec 2012 09:07:39 -0800 (PST), zyng <>
    wrote, quoted or indirectly quoted someone who said :

    >My Java program is started by using somebody's shell script. Inside his script:
    >
    >java -classpath his_lib/'*' Main


    you could write a dummy java program that execs your real program.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    Students who hire or con others to do their homework are as foolish
    as couch potatoes who hire others to go to the gym for them.
    Roedy Green, Dec 30, 2012
    #9
  10. zyng

    John L. Guest

    On Friday, December 28, 2012 12:07:39 PM UTC-5, zyng wrote:
    > Hi: My Java program is started by using somebody's shell script. Inside his script: java -classpath his_lib/'*' Main However, I also wish to set Java's classpath for my code to work and I am not allowed to change his script..(He: actually is a company. My program is running inside this company's main frame). So when JVM starts, the true classpath is my_lib/'*';his_lib/'*'.. Is that possible to do? Thank you.


    At the risk of stating the obvious, perhaps set the %CLASSPATH% environmentvariable (or its Unix equivalent) prior to invoking your colleague's script.
    John L., Dec 30, 2012
    #10
  11. zyng

    Arne Vajhøj Guest

    On 12/30/2012 2:50 PM, John L. wrote:
    > On Friday, December 28, 2012 12:07:39 PM UTC-5, zyng wrote:
    >> Hi: My Java program is started by using somebody's shell script.
    >>Inside his script: java -classpath his_lib/'*' Main However, I also wish
    >>to set Java's classpath for my code to work and I am not allowed to
    >>change his script.(He: actually is a company. My program is running
    >>inside this company's main frame). So when JVM starts, the true
    >>classpath is my_lib/'*';his_lib/'*'. Is that possible to do? Thank you.

    >
    > At the risk of stating the obvious, perhaps set the %CLASSPATH%
    > environment variable (or its Unix equivalent) prior to invoking your
    > colleague's script.


    The -cp argument override CLASSPATH env - it does not supplement it.

    Arne
    Arne Vajhøj, Dec 30, 2012
    #11
  12. zyng

    Arne Vajhøj Guest

    On 12/30/2012 10:53 AM, Roedy Green wrote:
    > On Fri, 28 Dec 2012 09:07:39 -0800 (PST), zyng <>
    > wrote, quoted or indirectly quoted someone who said :
    >> My Java program is started by using somebody's shell script. Inside his script:
    >>
    >> java -classpath his_lib/'*' Main

    >
    > you could write a dummy java program that execs your real program.


    OP could do that.

    But if is not an option to change the shell script, then it does
    not help.

    If it is an option to change the shell script, then the dummy
    program is not needed.

    Arne
    Arne Vajhøj, Dec 30, 2012
    #12
  13. On 12/30/2012 3:49 PM, Martin Gregorie wrote:
    > On Sun, 30 Dec 2012 11:50:48 -0800, John L. wrote:
    >
    >> On Friday, December 28, 2012 12:07:39 PM UTC-5, zyng wrote:
    >>> Hi: My Java program is started by using somebody's shell script. Inside
    >>> his script: java -classpath his_lib/'*' Main However, I also wish to
    >>> set Java's classpath for my code to work and I am not allowed to change
    >>> his script.(He: actually is a company. My program is running inside
    >>> this company's main frame). So when JVM starts, the true classpath is
    >>> my_lib/'*';his_lib/'*'. Is that possible to do? Thank you.

    >>
    >> At the risk of stating the obvious, perhaps set the %CLASSPATH%
    >> environment variable (or its Unix equivalent) prior to invoking your
    >> colleague's script.

    >
    > At the brisk of stating another obvious point, whats wrong with this
    > summary of the situation?
    >
    > 1) the owner of the computer wants your program to be run on it.
    > 2) an existing script must be changed for your program to run
    > 3) the computer's sysadmins won't let anybody else change scripts
    > on production systems. (a fairly common situation).
    >
    > However this leaves the obvious outstanding question: why won't the
    > sysadmins, i.e. 'the company', make the changes needed for your program
    > to run?


    Do you read Dilbert?

    :)

    Arne
    Arne Vajhøj, Dec 30, 2012
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Flip
    Replies:
    3
    Views:
    7,211
    Tony Morris
    Feb 9, 2004
  2. Gabe
    Replies:
    3
    Views:
    1,054
  3. Replies:
    2
    Views:
    730
  4. RalphLeon

    Java Classpath - Simple Question

    RalphLeon, Aug 3, 2007, in forum: Java
    Replies:
    3
    Views:
    383
    Mike Schilling
    Aug 3, 2007
  5. Replies:
    2
    Views:
    1,082
    Mike Schilling
    Mar 2, 2008
Loading...

Share This Page