简体   繁体   中英

maven-surefire-plugin fails with error “Cannot load 32-bit SWT libraries on 64-bit JVM”

I'm developing an Eclipse RCP. I'm using Jenkins as CI sever that builds the system and run the unit tests. I can run my unit tests from within the Eclipse IDE without any problem but when Jenkins try to do the same in the build job, I get the following error message:

[INFO] --- maven-surefire-plugin:2.18.1:test (test) @ net.morcate.console.scripting ---
[INFO] Surefire report directory: /var/lib/jenkins/jobs/Console-Devel/workspace/sssb-console/net.morcate.console.scripting/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Running net.morcate.console.scripting.views.browser.FileServerStatusListenerTest

Tests run: 10, Failures: 0, Errors: 10, Skipped: 0, Time elapsed: 1.353 sec <<< FAILURE! - in net.morcate.console.scripting.views.browser.FileServerStatusListenerTest
StatusChange_With_Status_INITIALIZING_Should_NOT_UpdateBrowser(net.morcate.console.scripting.views.browser.FileServerStatusListenerTest)  Time elapsed: 1.315 sec  <<< ERROR!
java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:263)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:240)
    at org.eclipse.swt.internal.C.<clinit>(C.java:21)
    at org.eclipse.swt.widgets.Display.<clinit>(Display.java:138)
    at sun.reflect.GeneratedSerializationConstructorAccessor7.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
    at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
    at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:111)
    at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:51)
    at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:54)
    at org.mockito.internal.MockitoCore.mock(MockitoCore.java:45)
    at org.mockito.Mockito.mock(Mockito.java:921)
    at org.mockito.internal.configuration.DefaultAnnotationEngine.processAnnotationOn(DefaultAnnotationEngine.java:61)
    at org.mockito.internal.configuration.DefaultAnnotationEngine.createMockFor(DefaultAnnotationEngine.java:36)
    at org.mockito.internal.configuration.DefaultAnnotationEngine.process(DefaultAnnotationEngine.java:85)
    at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:40)
    at org.mockito.MockitoAnnotations.scan(MockitoAnnotations.java:112)
    at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:95)
    at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl$1.withBefores(JUnit45AndHigherRunnerImpl.java:27)
    at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:268)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
    at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

Both computers are Linux Ubuntu 14.04LTS - 64 bits. So, my guess is that there is some configuration problem in my CI server.


This is what I have in the main pom file, but I don't say anywhere what architecture to use to run the unit tests:

<plugin>
    <groupId>${tycho-groupid}</groupId>
    <artifactId>target-platform-configuration</artifactId>
    <version>${tycho-version}</version>
    <configuration>
        <target>
            <artifact>
                <groupId>scripts.console</groupId>
                <artifactId>net.morcate.console.target</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <!-- This is the target file to be used to build the console. -->
                <classifier>consoleTest</classifier>
            </artifact>
        </target>
        <resolver>p2</resolver>
        <environments>
            <environment>
                <os>win32</os>
                <ws>win32</ws>
                <arch>x86</arch>
            </environment>
            <environment>
                <os>win32</os>
                <ws>win32</ws>
                <arch>x86_64</arch>
            </environment>
            <environment>
                <os>macosx</os>
                <ws>cocoa</ws>
                <arch>x86_64</arch>
            </environment>
            <environment>
                <os>linux</os>
                <ws>gtk</ws>
                <arch>x86</arch>
            </environment>
            <environment>
                <os>linux</os>
                <ws>gtk</ws>
                <arch>x86_64</arch>
            </environment>
            <environment>
                <os>solaris</os>
                <ws>gtk</ws>
                <arch>x86</arch>
            </environment>
            <environment>
                <os>solaris</os>
                <ws>gtk</ws>
                <arch>sparc</arch>
            </environment>
        </environments>
    </configuration>
</plugin>

If a change the order of the <environment> elements and I put the one for linux gtk x86_64 the first, then the tests are executed as expected. So the question is: How do I set the environment to run the test in my pom file?

The environment for the Tycho surefire test runtime is automatically derived from (in decreasing precedence):

  • properties configured in the Maven settings.xml,
  • system properties, and
  • project properties configured in the POMs.

However it seems that you don't use the tycho-surefire-plugin , but that you have manually configured the maven-surefire-plugin to run your tests.

To fix this problem, you probably only need to remove the maven-surefire-plugin configuration from you POM and make sure you are using the packaging type eclipse-test-plugin . That packaging type automatically includes the test execution with Tycho's surefire plugin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM