Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
billknop@gmail.com - 26 Mar 2007 20:57 GMT
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.
Gordon Beaton - 26 Mar 2007 21:12 GMT
> 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
[quoted text clipped - 3 lines]
> 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

--
opalpa opalpa@gmail.com http://opalpa.info - 27 Mar 2007 01:19 GMT
> 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
opalpa@gmail.com
http://opalpa.info/
billknop@gmail.com - 28 Mar 2007 20:16 GMT
On Mar 26, 7:19 pm, "opalpa opa...@gmail.com http://opalpa.info"
<opa...@gmail.com> wrote:
> > The .so must be loaded from the "real" filesystem, you can't load it
> > from inside the ear file.
[quoted text clipped - 8 lines]
> opalpa
> opa...@gmail.comhttp://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.
Gordon Beaton - 28 Mar 2007 21:05 GMT
> 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

--


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.