spring-jnr

A library to inject JNR native libraries to Spring beans

License

License

Categories

Categories

JNR Development Tools Native
GroupId

GroupId

com.github.goto1134
ArtifactId

ArtifactId

spring-jnr
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

spring-jnr
A library to inject JNR native libraries to Spring beans
Project URL

Project URL

https://github.com/goto1134/spring-jnr
Source Code Management

Source Code Management

https://github.com/goto1134/spring-jnr

Download spring-jnr

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.goto1134/spring-jnr/ -->
<dependency>
    <groupId>com.github.goto1134</groupId>
    <artifactId>spring-jnr</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.goto1134/spring-jnr/
implementation 'com.github.goto1134:spring-jnr:1.0'
// https://jarcasting.com/artifacts/com.github.goto1134/spring-jnr/
implementation ("com.github.goto1134:spring-jnr:1.0")
'com.github.goto1134:spring-jnr:jar:1.0'
<dependency org="com.github.goto1134" name="spring-jnr" rev="1.0">
  <artifact name="spring-jnr" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.goto1134', module='spring-jnr', version='1.0')
)
libraryDependencies += "com.github.goto1134" % "spring-jnr" % "1.0"
[com.github.goto1134/spring-jnr "1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.github.jnr : jnr-ffi jar 2.1.6
org.springframework : spring-context jar 4.3.9.RELEASE

test (3)

Group / Artifact Type Version
org.springframework : spring-test jar 4.3.9.RELEASE
org.hamcrest : hamcrest-all jar 1.3
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

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;

Versions

Version
1.0