4

我正在尝试在 Maven 项目中从 JUnit 内部使用 Voldemort。当以下代码编译时,它没有成功执行:

@Before
public void setUp() throws Exception
{
    // Start Voldemort
    VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable();
    VoldemortServer server = new VoldemortServer(config);
    server.start();
}

相反,会引发此异常:

java.lang.UnsatisfiedLinkError: voldemort.utils.JNAUtils.mlockall(I)I
    at voldemort.utils.JNAUtils.mlockall(Native Method)
    at voldemort.utils.JNAUtils.tryMlockall(JNAUtils.java:51)
    at voldemort.server.VoldemortServer.startInner(VoldemortServer.java:251)
    at voldemort.server.AbstractService.start(AbstractService.java:62)
    at a.b.c.FunctionalTest.setUp(FunctionalTest.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
    at $Proxy0.invoke(Unknown Source)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

知道如何解决这个问题吗?

4

1 回答 1

2

请注意堆栈跟踪中的这一行

在 voldemort.utils.JNAUtils.mlockall(本机方法)

这表明无论调用什么代码,都通过JNI. UnsatisfiedLinkedError在加载请求加载此的类时,JVM 无法加载本机库时遇到。

为确保您的代码可以加载 ddl / so 文件,请使用以下 java 系统属性,

-Djava.library.path=/path/to/directory/包含/native/libraries

或者,您可以将相同的目录添加到PATHWindows 上的环境变量或LD_LIBRARY_PATHLinux 上的变量中。

查看http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html此页面描述了如何将系统属性传递给maven-surefire-plugin负责在 Maven 中运行测试的系统属性。

于 2012-10-11T07:58:14.723 回答