Skip to content

Spring extension to load native libraries via JNR.

License

Notifications You must be signed in to change notification settings

goto1134/spring-jnr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-jnr

Spring extension to load native libraries via jnr-ffi.

Tests are written for windows

Get it

Gradle

dependencies {
    compile group: 'com.github.goto1134', name: 'spring-jnr', version: '1.0'
}

Maven

<dependencies>
    <dependency>
      <groupId>com.github.goto1134</groupId>
      <artifactId>spring-jnr</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
    </dependency>
</dependencies>

Use it

  1. Register BeanPostProcessor
@Bean
public BeanPostProcessor nativeLibraryBeanPostProcessor() {
    return new NativeLibraryBeanPostProcessor();
}
  1. Declare configuration qualifier
@Qualifier
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MicrosoftVisualCRuntime {
}
  1. Declare library configuration
@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());
    }
}
  1. Mark all libraries with the same qualifier
@MicrosoftVisualCRuntime
public interface PseudoRandomSequenceGenerator {
    int rand();
}
  1. Mark all fields where injection is needed
@NativeLibrary
private PseudoRandomSequenceGenerator generator;

About

Spring extension to load native libraries via JNR.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages