Код: Выделить всё
// Java Program to Illustrate Native Keyword // Inside DLL named:
NameOfDLLFile
// Main class // NativeDemo // Java Program to Illustrate Native
Keyword
class NaitiveDemo {
// Native method declaration
public native void test();
// Load the native library
/*static {
System.loadLibrary("NaitiveDemo"); // Load the DLL or shared library
}*/ static{
try {
System.loadLibrary("NaitiveDemo");
} catch (UnsatisfiedLinkError e) {
System.err.println("Error loading native library: " + e.getMessage());
} }
public static void main(String[] args) {
NaitiveDemo obj = new NaitiveDemo();
obj.test(); // Call the native method
} }
Код: Выделить всё
// C++ Program to Be Shared In DLL to Illustrate
// Native Method in Java
// Importing required libraries
#include
using namespace std;
// Method 2
// Native
void test(int var) { cout java -Djava.library.path="C:\Users\pcuser\23 july 2024\theory\NaitiveDemo" NaitiveDemo
Код: Выделить всё
Error: Could not find or load main class .library.path=C:\Users\pcuser\23 july 2024\theory\NaitiveDemo
Caused by: java.lang.ClassNotFoundException: /library/path=C:\Users\pcuser\23 july 2024\theory\NaitiveDemo
PS C:\Users\pcuser\23 july 2024\theory\NaitiveDemo
Код: Выделить всё
java --version
openjdk 17.0.12 2024-07-16
OpenJDK Runtime Environment Temurin-17.0.12+7 (build 17.0.12+7)
OpenJDK 64-Bit Server VM Temurin-17.0.12+7 (build 17.0.12+7, mixed mode, sharing)
на основании ответа ниже я выполняю это как
PS C:\Users\pcuser\23 июль 2024 г. \theory\NaitiveDemo> java '-Djava.library.path=C:\Users\pcuser\23 июля 2024 г.\theory\NaitiveDemo' NaitiveDemo
Теперь я получаю сообщение об ошибке
Теперь я получаю сообщение об ошибке р>
Код: Выделить всё
NaitiveDemo
Exception in thread "main" java.lang.UnsatisfiedLinkError: 'void NaitiveDemo.test()'
at NaitiveDemo.test(Native Method)
at NaitiveDemo.main(NaitiveDemo.java:27)
Подробнее здесь: https://stackoverflow.com/questions/787 ... on-problem
Мобильная версия