Skip to content

Commit

Permalink
fix loading native libraries from build directory
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Sep 14, 2024
1 parent 87117fb commit 1a55180
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"configurations": [
{
"type": "java",
"name": "Launch Current File",
"request": "launch",
"mainClass": "${file}",
"projectName": "monero-java",
"vmArgs": "-Djava.library.path=./build",
}
]
}
4 changes: 3 additions & 1 deletion src/main/java/monero/common/MoneroUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static void loadNativeLibrary() {
try {
String libName = (System.getProperty("os.name").toLowerCase().contains("windows") ? "lib" : "") + "monero-java";
System.loadLibrary(libName);
if (isNativeLibraryLoaded()) return;
} catch (Exception | UnsatisfiedLinkError e) {
// ignore error
}
Expand Down Expand Up @@ -93,13 +94,14 @@ public static void loadNativeLibrary() {
libraryCppFile = "libmonero-cpp.dylib";
libraryJavaFile = "libmonero-java.dylib";
} else {
throw new UnsupportedOperationException("Unsupported operating system: " + osName);
throw new MoneroError("Unsupported operating system: " + osName);
}

// copy all library files to temp directory
tempDir = Files.createTempDirectory("libmonero");
for (String libraryFile : libraryFiles) {
try (InputStream inputStream = MoneroUtils.class.getResourceAsStream(libraryPath + libraryFile); OutputStream outputStream = Files.newOutputStream(tempDir.resolve(libraryFile))) {
if (inputStream == null) throw new MoneroError("Missing native library for monero-java: " + libraryFile);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
Expand Down

0 comments on commit 1a55180

Please sign in to comment.