diff --git a/pom.xml b/pom.xml index af2163c..79211f8 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,8 @@ 17 3.1.2 + 2.14.0 + 3.13.0 1.5.3.Final @@ -32,9 +34,15 @@ - com.github.jnr - jnr-ffi - 2.2.15 + net.java.dev.jna + jna + 5.13.0 + + + + net.java.dev.jna + jna-platform + 5.13.0 @@ -54,6 +62,20 @@ test + + + commons-io + commons-io + ${commons-io.version} + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.mapstruct @@ -78,6 +100,28 @@ + + org.springframework.boot + spring-boot-maven-plugin + + false + + + org.projectlombok + lombok + + + + + + repackage + + repackage + + + + + org.apache.maven.plugins maven-compiler-plugin @@ -121,6 +165,16 @@ @ false + + UTF-8 + + pfx + crt + cer + key + dll + so + diff --git a/src/main/java/cn/skcks/jnr/sevenzip/Application.java b/src/main/java/cn/skcks/jnr/sevenzip/Application.java index daa658b..76fe553 100644 --- a/src/main/java/cn/skcks/jnr/sevenzip/Application.java +++ b/src/main/java/cn/skcks/jnr/sevenzip/Application.java @@ -1,7 +1,9 @@ package cn.skcks.jnr.sevenzip; +import cn.skcks.jnr.sevenzip.hello.Hello; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; @SpringBootApplication public class Application { diff --git a/src/main/java/cn/skcks/jnr/sevenzip/hello/Hello.java b/src/main/java/cn/skcks/jnr/sevenzip/hello/Hello.java new file mode 100644 index 0000000..79e54c3 --- /dev/null +++ b/src/main/java/cn/skcks/jnr/sevenzip/hello/Hello.java @@ -0,0 +1,37 @@ +package cn.skcks.jnr.sevenzip.hello; + +import com.sun.jna.Library; +import com.sun.jna.Native; +import jakarta.annotation.PostConstruct; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class Hello { + @PostConstruct + void test(){ + context(); + }; + + public interface HelloLib extends Library { + HelloLib INSTANCE = Native.load(loadLib("/lib/win64/hello.dll"), HelloLib.class); + + int add(int a,int b); + } + + @SneakyThrows + synchronized static String loadLib(String resourcePath){ + String path = Native.extractFromResourcePath(resourcePath).getAbsolutePath(); + log.info("{}", path); + return path; + } + + @SneakyThrows + public void context(){ + log.info("测试"); + HelloLib hello = HelloLib.INSTANCE; + log.info("{}", hello.add(1,2)); + } +} diff --git a/src/main/resources/lib/win64/hello.dll b/src/main/resources/lib/win64/hello.dll new file mode 100644 index 0000000..daccda1 Binary files /dev/null and b/src/main/resources/lib/win64/hello.dll differ diff --git a/src/test/java/cn.skcks.jnr.sevenzip/sevenzip/SimpleTest.java b/src/test/java/cn.skcks.jnr.sevenzip/sevenzip/SimpleTest.java index 68d211a..d7379a9 100644 --- a/src/test/java/cn.skcks.jnr.sevenzip/sevenzip/SimpleTest.java +++ b/src/test/java/cn.skcks.jnr.sevenzip/sevenzip/SimpleTest.java @@ -1,5 +1,8 @@ package cn.skcks.jnr.sevenzip.sevenzip; +import com.sun.jna.Library; +import com.sun.jna.Native; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -10,8 +13,25 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @SpringBootTest(classes = ApplicationTest.class) public class SimpleTest { + + public interface HelloLib extends Library { + HelloLib INSTANCE = Native.load(loadLib("/lib/win64/hello.dll"), HelloLib.class); + + int add(int a,int b); + } + + @SneakyThrows + synchronized static String loadLib(String resourcePath){ + String path = Native.extractFromResourcePath(resourcePath).getAbsolutePath(); + log.info("{}", path); + return path; + } + @Test - void context(){ + @SneakyThrows + public void context(){ log.info("测试"); + HelloLib hello = HelloLib.INSTANCE; + log.info("{}", hello.add(1,2)); } }