Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion netcdf4/src/main/java/ucar/nc2/ffi/netcdf/NetcdfClibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,23 @@ public class NetcdfClibrary {

/**
* Set the path and name of the netcdf c library.
* Must be called before load() is called.
* <p>
* Must be called prior to calling {@link #isLibraryPresent() isLibraryPresent}
* or {@link #getForeignFunctionInterface() getForeignFunctionInterface}, as
* the C library can only be successfully loaded once.
*
* @param jna_path path to shared libraries, may be null. If null, will look for system property
* "jna.library.path", then environment variable "JNA_PATH". If set, will set
* the environment variable "JNA_PATH".
* @param lib_name library name, may be null. If null, will use "netcdf".
*/
public static void setLibraryNameAndPath(@Nullable String jna_path, @Nullable String lib_name) {

if (nc4 != null) {
log.warn("netCDF-C library already set, ignoring.");
return;
}

lib_name = Strings.emptyToNull(lib_name);

if (lib_name == null) {
Expand All @@ -61,6 +70,11 @@ public static void setLibraryNameAndPath(@Nullable String jna_path, @Nullable St

libName = lib_name;
jnaPath = jna_path;

if ((isClibraryPresent == null || !isClibraryPresent) && jnaPath != null) {
// call load to retry loading, but this time with jnaPath set
load();
}
}

/**
Expand Down
16 changes: 13 additions & 3 deletions netcdf4/src/main/java/ucar/nc2/jni/netcdf/Nc4Iosp.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,26 @@ public class Nc4Iosp extends AbstractIOServiceProvider implements IOServiceProvi
private static final boolean transcodeStrings = Charset.defaultCharset() != StandardCharsets.UTF_8;

/**
* set the path and name of the netcdf c library.
* must be called before load() is called.
* Set the path and name of the netcdf c library.
* <p>
* This method will only work if the netCDF-C library was not found on the
* system path. If you need to use a specific version of the C library, and
* you have a different version on a system path, do not use this method.
* Instead, call {@link NetcdfClibrary#setLibraryNameAndPath(String, String)
* NetcdfClibrary.setLibraryNameAndPath} prior to any uses of
* the Nc4Iosp class.
*
* @param jnaPath path to shared libraries
* @param libName library name
* @deprecated use NetcdfClibrary.setLibraryNameAndPath
*/
@Deprecated
public static void setLibraryAndPath(String jnaPath, String libName) {
NetcdfClibrary.setLibraryNameAndPath(jnaPath, libName);
if (nc4 != null) {
log.warn("Library already set, ignoring.");
} else {
NetcdfClibrary.setLibraryNameAndPath(jnaPath, libName);
}
}

/**
Expand Down