[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDFJava #MDA-777673]: netcdf-4 library loading



Hi Vikram,

> I used Nc4Iosp.SetLibraryAndPath() to specify a location that does not
> exist, but there was no error message or failure.

Nc4Iosp.setLibraryAndPath() doesn't actually attempt to load libnetcdf, which 
is why you aren't seeing an error. Instead try something like:
        Nc4Iosp.setLibraryAndPath("/Users/cwardgar/Desktop/foo", "netcdf");
        System.out.printf("libnetcdf is present = %s%n", 
Nc4Iosp.isClibraryPresent());

When I've given the wrong path I get:
    Jul 27, 2016 4:26:49 PM ucar.nc2.jni.netcdf.Nc4Iosp load
    WARNING: Nc4Iosp: NetCDF-4 C library not present 
(jna_path='/Users/cwardgar/Desktop/foo', libname='netcdf').
    java.lang.UnsatisfiedLinkError: Unable to load library 'netcdf': Native 
library (darwin/libnetcdf.dylib) not found in resource path ([...])
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:271)
        ...

Note that you'll need an SLF4J logger [1] on the classpath to see that message.

>Is there a path it defaults to looking for the library in?

The shared library loader on your system has a default search path [2], but 
NetCDF-Java doesn't (anymore). For example, if your binaries are in 
/usr/local/lib, they'll almost certainly be found without any extra effort from 
you.

> Also, I was wondering if the netcdf-Java classes relevant to netcdf-4 IO
> could be repackaged in a smaller jar file?

Do you use Maven or Gradle? If so, you only need to include the "netcdf4" 
module [3]. Then, all of its transitive dependencies will be pulled in 
automatically.

Or maybe you want a fat jar like netcdfAll.jar that includes everything 
necessary to work with NetCDF-4, and nothing else? If so, that's not an 
artifact we normally publish. I could easily build one for you if you want, but 
it's be a one-off.

Cheers,
Christian

[1] 
http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/reference/BuildDependencies.html#_logging
[2] 
http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/reference/netcdf4Clibrary.html#loading
[3] 
http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/reference/netcdf4Clibrary.html

Ticket Details
===================
Ticket ID: MDA-777673
Department: Support netCDF Java
Priority: Normal
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.