Java 如何从JUnit内部使用伏地魔服务器?
我试图在Maven项目中从JUnit内部使用伏地魔。编译以下代码时,无法成功执行:Java 如何从JUnit内部使用伏地魔服务器?,java,maven,junit,voldemort,Java,Maven,Junit,Voldemort,我试图在Maven项目中从JUnit内部使用伏地魔。编译以下代码时,无法成功执行: @Before public void setUp() throws Exception { // Start Voldemort VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable(); VoldemortServer server = new VoldemortServer(config);
@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)
知道如何解决这个问题吗?在stacktrace中记下这一行 在voldemort.utils.JNAUtils.mlockall(本机方法) 这表明无论调用什么代码,都会通过
JNI
使用一些本机库<当JVM在加载请求加载本机库的类时无法加载本机库时,会遇到code>unsatifiedlinkederror
要确保代码可以加载ddl/so文件,请使用以下java系统属性:
-Djava.library.path=/path/to/directory/containing/native/libraries
或者,您可以将相同的目录添加到windows上的PATH
环境变量,或Linux上的LD\u LIBRARY\u PATH
变量
查看此页面,了解如何将系统属性传递给负责在maven中运行测试的maven surefire plugin
。请不要使用该名称--称之为“你知道谁”