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

B

billknop

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.
 
G

Gordon Beaton

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

--
 
O

opalpa opalpa

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
(e-mail address removed)
http://opalpa.info/
 
B

billknop

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
(e-mail address removed)://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.
 
G

Gordon Beaton

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

--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top