在使用Maven在Intellij IDEA中运行单元测试时,zmq失败

时间:2012-08-16 10:54:42

标签: maven intellij-idea zeromq java.library.path jzmq

当我在Intellij IDEA(Ultimate)11.1中使用maven进行单元测试时。我得到了以下例外。

-------------------------------------------------------------------------------
Test set: myapp.messaging.MQServiceTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.026 sec <<< FAILURE!
testEnqueueAndDequeue(myapp.messaging.MQServiceTest)  Time elapsed: 0.024 sec  <<< ERROR!
java.lang.UnsatisfiedLinkError: no jzmq in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856)
    at java.lang.Runtime.loadLibrary0(Runtime.java:845)
    at java.lang.System.loadLibrary(System.java:1084)
    at org.zeromq.ZMQ.<clinit>(ZMQ.java:34)
    at myapp.messaging.MQClient.<init>(MQClient.java:34)
    at myapp.messaging.MQServiceTest.testEnqueueAndDequeue(MQServiceTest.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    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.InvokeMethod.evaluate(InvokeMethod.java:20)
    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:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

从互联网搜索后,似乎zmq缺少java.library.path - usr / local / lib。所以我尝试将“-Djava.library.path = / usr / local / lib”添加到maven的vm选项中,但仍然没有用。

注意:

  1. 我可以用bash中的“mvn test”通过测试。 (我在〜/ .profile中添加了“export LD_LIBRARY_PATH = / usr / local / lib”)

  2. 我在pom中配置了这个而不是jzmq,因为我需要在我的项目中使用storm并且风暴引用了jzmq。

  3. <dependency>
        <groupId>storm</groupId>
        <artifactId>storm</artifactId>
        <version>0.7.4</version>
    </dependency>
    

1 个答案:

答案 0 :(得分:0)

我尝试从终端启动Intellij,它运行正常。当我从Ubuntu的启动面板启动它时,它不是从我的任何登录环境变量开始。选中http://blog.bluecalyx.org/2009/07/02/missing-environment-variables-in-intellij/后,我使用 bash --login IDEAPATH / bin / idea.sh 更新了Intellij桌面文件中的exec,然后世界变得和平。

我仍然感到困惑的是,即使我在Intellij maven runner设置中添加了 -Djava.library.path = / usr / local / lib ,它也无效。

最后,只是提醒一下,在开始使用ZMQ和jzmq之前,有必要安装它。请参阅www.zeromq.org/intro:get-the-software和www.zeromq.org/bindings:java