https://github.com/goto1134/spring-jnr
Spring extension to load native libraries via JNR.
https://github.com/goto1134/spring-jnr
java jnr spring
Last synced: 5 months ago
JSON representation
Spring extension to load native libraries via JNR.
- Host: GitHub
- URL: https://github.com/goto1134/spring-jnr
- Owner: goto1134
- License: mit
- Created: 2017-07-04T19:33:26.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-23T19:53:11.000Z (almost 9 years ago)
- Last Synced: 2025-06-03T10:08:51.799Z (about 1 year ago)
- Topics: java, jnr, spring
- Language: Java
- Size: 26.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spring-jnr
Spring extension to load native libraries via [jnr-ffi](https://github.com/jnr/jnr-ffi).
**Tests are written for windows**
## Get it
### Gradle
```groovy
dependencies {
compile group: 'com.github.goto1134', name: 'spring-jnr', version: '1.0'
}
```
### Maven
```xml
com.github.goto1134
spring-jnr
1.0
compile
```
## Use it
0. Register `BeanPostProcessor`
```java
@Bean
public BeanPostProcessor nativeLibraryBeanPostProcessor() {
return new NativeLibraryBeanPostProcessor();
}
```
1. Declare configuration qualifier
```java
@Qualifier
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MicrosoftVisualCRuntime {
}
```
2. Declare library configuration
```java
@MicrosoftVisualCRuntime
@Component
public class MicrosoftVisualCRuntimeConfiguration
implements NativeLibraryConfiguration {
@Override
public LibraryInfo getLibraryInfo() {
if (Platform.getNativePlatform()
.getOS() != Platform.OS.WINDOWS) {
throw new IllegalStateException("Must be windows OS");
}
return new LibraryInfo("msvcrt", "", CallingConvention.STDCALL, true, IdentityFunctionMapper.getInstance());
}
}
```
3. Mark all libraries with the same qualifier
```java
@MicrosoftVisualCRuntime
public interface PseudoRandomSequenceGenerator {
int rand();
}
```
4. Mark all fields where injection is needed
```java
@NativeLibrary
private PseudoRandomSequenceGenerator generator;
```