System.load() & .loadLibrary() - with file not in java.library.path property

Discussion in 'Java' started by billknop@gmail.com, Mar 26, 2007.

  1. Guest

    I have run into a problem at my company where I may not be allowed to
    install a necessary library file on the server immediately. If
    possible, I would have to deploy it with my .ear file.

    I am trying to load the SAPJCo object and it requires their
    libsapjcorfc.so file to reside on the server itself. The people that
    own the servers (at this company, the support is outsourced to a 3rd
    party..) are telling me that I won't be able to add any new paths to
    the java.library.path or add the .so library file to an existing path
    (like the /usr/lib directory..). I have de-compiled SAP's sapjco.jar
    file and have found where they are loading the library.

    My question is that I was wondering if I could store the library file
    in the WEB-INF directory and give a "real" path name to the
    System.load method?
    For instance:
    System.load(/opt/was51/AppServer/installedApps/WAS51TST/<appname>.ear/
    <appname>web.war/WEB-INF/lib/libsapjcorfc.so);

    OR if there were any other method of loading a .so library file that I
    am missing?

    The environment is running WSAD 5.1 on IBM AIX servers.

    Thanks for your help.
    , Mar 26, 2007
    #1
    1. Advertising

  2. On 26 Mar 2007 12:57:02 -0700, wrote:
    > My question is that I was wondering if I could store the library
    > file in the WEB-INF directory and give a "real" path name to the
    > System.load method?
    >
    > For instance:
    > System.load(/opt/was51/AppServer/installedApps/WAS51TST/<appname>.ear/
    ><appname>web.war/WEB-INF/lib/libsapjcorfc.so);


    [...]

    > The environment is running WSAD 5.1 on IBM AIX servers.


    The .so must be loaded from the "real" filesystem, you can't load it
    from inside the ear file.

    You can put it anywhere in the filesystem and use
    System.load("/full/path/to/libsapjcorfc.so");

    Or, to use System.loadLibrary("sapjcorfc"), you need to put it in one
    of the following:

    - LD_LIBRARY_PATH (AIX equivalent?)
    - java.library.path
    - standard place like /lib, /usr/lib and so on

    /gordon

    --
    Gordon Beaton, Mar 26, 2007
    #2
    1. Advertising


  3. > The .so must be loaded from the "real" filesystem, you can't load it
    > from inside the ear file.


    An idea, which presumes the ability to getResourceAsStream from an ear
    file like one can from a jar file:

    Perform getResourceAsStream on so file that is packed inside of jar/
    ear, stream it to a temporary file on file system, load the temporary
    file.

    opalpa

    http://opalpa.info/
    opalpa http://opalpa.info, Mar 27, 2007
    #3
  4. Guest

    On Mar 26, 7:19 pm, "opalpa http://opalpa.info"
    <> wrote:
    > > The .so must be loaded from the "real" filesystem, you can't load it
    > > from inside the ear file.

    >
    > An idea, which presumes the ability to getResourceAsStream from an ear
    > file like one can from a jar file:
    >
    > Perform getResourceAsStream on so file that is packed inside of jar/
    > ear, stream it to a temporary file on filesystem, loadthe temporary
    > file.
    >
    > opalpa
    > ://opalpa.info/


    Ok, I am going to try and give this method a shot. I haven't worked
    with file io and input/output streams.

    --code--

    File file = File.createTempFile("sapjcotest", ".so");
    file.deleteOnExit();

    InputStream inStream =
    ClassLoader.getSystemClassLoader().getResourceAsStream("/opt/was51/
    AppServer/installedApps/WAS51TST/esstst4.ear/esstst4web.war/WEB-INF/
    lib/libsapjcorfc.so");

    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    out.write(inStream.hashCode());
    out.close();
    System.load(file.getCanonicalPath());

    --code--

    I'm fairly confident that I have it started the right way.. The
    inStream object is always null and even if that did work, I can't
    figure out how to write that stream to the BufferedWriter object.
    Could you assist with that?

    Thanks again for your help.
    , Mar 28, 2007
    #4
  5. On 28 Mar 2007 12:16:56 -0700, wrote:
    > I'm fairly confident that I have it started the right way.. The
    > inStream object is always null and even if that did work, I can't
    > figure out how to write that stream to the BufferedWriter object.
    > Could you assist with that?


    I can't say why your inputStream is null from the example.

    However, don't *ever* use Readers or Writers for binary data! You will
    corrupt the file. Read from the InputStream until you reach EOF,
    writing each chunk to an OutputStream (e.g. a FileOutputStream).

    /gordon

    --
    Gordon Beaton, Mar 28, 2007
    #5
    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. Matthew Zimmer

    System.loadLibrary problem

    Matthew Zimmer, Dec 16, 2003, in forum: Java
    Replies:
    6
    Views:
    16,150
    Matthew Zimmer
    Dec 17, 2003
  2. Roedy Green

    System.loadLibrary

    Roedy Green, Aug 1, 2005, in forum: Java
    Replies:
    0
    Views:
    697
    Roedy Green
    Aug 1, 2005
  3. Replies:
    1
    Views:
    493
    Gordon Beaton
    Feb 6, 2006
  4. Replies:
    2
    Views:
    811
    Nigel Wade
    Nov 24, 2006
  5. Philipp Kraus

    System.load / System.loadLibrary

    Philipp Kraus, Oct 9, 2011, in forum: Java
    Replies:
    8
    Views:
    1,830
    John B. Matthews
    Oct 10, 2011
Loading...

Share This Page